Error Handling
How to handle errors from the TypeScript SDK and HTTP API.
TypeScript SDK
All API errors throw a WordAuthError with message and status properties.
import { WordAuth, WordAuthError } from "wordauth";
const wordauth = new WordAuth("sk_live_...");
try {
const { otp_id, code } = await wordauth.generate();
} catch (err) {
if (err instanceof WordAuthError) {
console.error(`API error ${err.status}: ${err.message}`);
}
}
HTTP API
Non-2xx responses include a JSON body with a detail field describing the error. For 422 validation errors the field is an array.
// 403 — Invalid API key
{ "detail": "Invalid API key" }
// 422 — Validation error
{
"detail": [
{
"loc": ["body", "code"],
"msg": "field required",
"type": "missing"
}
]
}
// 500 — Server error
{ "detail": "Internal server error" }
Status codes
| Status | Meaning |
|---|---|
| 0 | Network / client error (SDK only) |
| 400 | Bad request |
| 403 | Invalid API key |
| 410 | OTP expired |
| 422 | Validation error |
| 429 | Rate limit exceeded |
| 500 | Server error |
Requirements
- •TypeScript SDK: Node.js 18+ (uses native
fetch) or any modern browser - •HTTP API: any language or runtime that can make HTTPS requests
Support
Need help? We're here for you.