Skip to main content

Exception hierarchy

All errors thrown by the SDK extend Law4DevsError, which itself extends the built-in Error. Use instanceof checks to handle specific error types.
Every error class exposes a statusCode property with the underlying HTTP status code.

Basic try/catch


Auto-retry behaviour

The SDK automatically retries on RateLimitError (429) and ServerError (5xx) using exponential backoff with jitter. Only after all retries are exhausted is the error thrown to your code.
Timeouts are enforced via AbortController, so they apply per-attempt (not across all retries combined).
NotFoundError and ValidationError are never retried — they indicate client-side issues that will not resolve on retry.

TypeScript narrowing with a typed helper

Define a safeGet helper to return a typed result or a structured error without propagating exceptions:

Handling errors inside for await

Errors thrown during iter() or iterDeadlines() are propagated out of the for await loop. Wrap the loop in try/catch to handle them:

Error reference

ClassHTTP StatusWhen thrownRetried?
NotFoundError404Requested resource does not existNo
ValidationError422Invalid parameters or queryNo
RateLimitError429Too many requestsYes
ServerError5xxServer-side errorYes
Law4DevsErroranyBase class — catch-allDepends
After all retries are exhausted, RateLimitError and ServerError are thrown normally. Always include these in your catch blocks for production code.