PBJ SDK documentation

Errors & cancellation

Handle authentication, validation, network, timeout, rate-limit, and cancellation failures with typed SDK errors.

Handle errors

ts
import {
  PBJError,
  PBJAuthenticationError,
} from "pbjspace";

try {
  await pbj.projects.list();
} catch (error) {
  if (error instanceof PBJAuthenticationError) {
    console.error("Check the server API key");
  } else if (error instanceof PBJError) {
    console.error(error.code, error.status, error.requestId);
  } else {
    throw error;
  }
}

Error types

ErrorWhen it occurs
PBJAuthenticationError401 or 403
PBJValidationError400, 422, or local validation
PBJNotFoundError404
PBJRateLimitErrorFinal 429 response
PBJNetworkErrorFetch or transport failure
PBJTimeoutErrorRequest deadline expires
PBJAbortErrorCaller cancels the request

Cancel a request

ts
const controller = new AbortController();
const pending = pbj.projects.list({ signal: controller.signal });

controller.abort();
await pending;

Retry behavior

GET requests retry 429, 500, 502, 503, and 504 responses while attempts remain. Mutations, validation failures, network failures, and cancellation are not retried.