Skip to content

Errors

Failed API responses throw WynnApiError subclasses. Prefer instanceof checks against the specific class.

ts
import { WynnApiError, WynnClient } from "@wynnjs/api";

const client = new WynnClient();

try {
  await client.player.getPlayer("DefinitelyNotARealPlayer_12345");
} catch (error) {
  if (error instanceof WynnApiError.NotFound) {
    console.error("Player not found:", error.detail);
  } else if (error instanceof WynnApiError.Forbidden) {
    console.error("Profile is private:", error.detail);
  } else if (error instanceof WynnApiError.TooManyRequest) {
    console.error("Rate limited:", error.detail);
  } else if (error instanceof WynnApiError.MultipleObjectsReturned) {
    console.error("Ambiguous match:", error.objects);
  } else if (error instanceof WynnApiError) {
    console.error(error.error, error.status, error.detail);
  } else {
    throw error;
  }
}

The wire format matches the official exceptions shape (error, detail, code).

Properties

PropertyTypeDescription
errorstringMachine-readable name (NotFound, …)
detailstringHuman-readable message
codenumberWynncraft error code
statusnumberHTTP status
identifier?stringResource identifier when present
objects?MultipleObjectsMapOnly on MultipleObjectsReturned

Subclasses

Access via WynnApiError.<Name>:

ClassTypical meaning
NotFoundMissing resource
ForbiddenPrivate profile / insufficient access
TooManyRequestRate limited (API spelling)
MultipleObjectsReturnedAmbiguous query; see objects
InvalidFormErrorBad form body
InvalidQueryParamsErrorBad query params
MalformedPayloadUnparseable body
MalformedTokenErrorBad token format
InvalidTokenErrorRejected token
CSRFErrorCSRF failure
PaginationErrorBad page / pagination state
MethodNotAllowedWrong HTTP method
InternalErrorUpstream failure
InvalidCharacterUUIDBad character UUID
NoCharacterFoundCharacter missing
MalformedPrefixErrorBad guild prefix
InvalidTreeBad ability / class tree

Unknown error names still throw a base WynnApiError with the parsed body fields.

MultipleObjectsReturned

Some queries can match more than one resource. The API returns code 300 with an objects map. The client surfaces that as WynnApiError.MultipleObjectsReturned.

ts
if (error instanceof WynnApiError.MultipleObjectsReturned) {
  for (const [id, entry] of Object.entries(error.objects ?? {})) {
    console.log(id, entry.username ?? entry.name);
  }
}

Full retry / UX pattern: Ambiguous matches cookbook.

Non-API failures

Network errors and non-JSON responses are not wrapped — they rethrow as the underlying Axios / runtime error. Only Wynncraft error bodies become WynnApiError.

Unofficial TypeScript tooling for the Wynncraft API