Detecte/docs

Errors

The SDK throws typed errors so you can pattern-match without parsing strings.

import {
  DetecteError,
  DetecteApiError,
  DetecteAuthError,
  DetecteValidationError,
  DetecteRateLimitError,
  DetecteNetworkError,
  DetecteTimeoutError,
} from "@detecte/sdk";
 
try {
  await detecte.verify(...);
} catch (e) {
  if (e instanceof DetecteRateLimitError) {
    // back off using e.retryAfterMs
  } else if (e instanceof DetecteAuthError) {
    // bad / revoked key
  } else if (e instanceof DetecteValidationError) {
    // input shape was rejected by the API
  } else if (e instanceof DetecteTimeoutError) {
    // didn't return within `timeout`
  } else if (e instanceof DetecteApiError) {
    // 4xx/5xx with a structured body
    console.error(e.code, e.status, e.body);
  } else {
    throw e;
  }
}

All Detecte errors extend DetecteError, which extends Error. They carry a stable code, an HTTP status (when applicable), and the response body.