JavaScript / TypeScript
Errors
Every error thrown by the SDK extends UmanthirError. Errors from the API extend APIError, which carries status, apiMessage (the API's error.message), method, url, headers, body, retryAfter (seconds) and apiVersion.
| Class | When |
|---|---|
ValidationError | An argument was rejected before sending the request (bad name, page, level, ...). |
ConnectionError | The API could not be reached (DNS, TLS, connection reset, offline). |
TimeoutError | An attempt took longer than timeout (extends ConnectionError). |
AbortError | The request was cancelled through your signal. |
BadRequestError | 400: the API rejected an argument (Unknown vocation., Invalid page., ...). |
NotFoundError | 404: character, guild, world, house, item or route not found. |
RateLimitError | 429: rate limit exceeded; rateLimit holds { limit, remaining, reset }. |
UpstreamError | 502 or 520: the API could not read tibia.com. |
ServiceUnavailableError | 503; reason is "maintenance", "busy", "wiki_unavailable" or "unknown". |
APIError | Any other error status. |
ts
import { RateLimitError, ServiceUnavailableError } from "@umanthir/sdk";
try {
await client.guilds.get("Alanui Institute");
} catch (error) {
if (error instanceof RateLimitError) console.log(`Try again in ${error.retryAfter} s`);
else if (error instanceof ServiceUnavailableError && error.reason === "maintenance") {
console.log("tibia.com is under maintenance");
} else throw error;
}In the browser bundle the classes are available on the global: Umanthir.NotFoundError, Umanthir.RateLimitError, and so on.
Next: Warnings.