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

StatusMeaning
0Network / client error (SDK only)
400Bad request
403Invalid API key
410OTP expired
422Validation error
429Rate limit exceeded
500Server 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.