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
| Error | When it occurs |
|---|---|
PBJAuthenticationError | 401 or 403 |
PBJValidationError | 400, 422, or local validation |
PBJNotFoundError | 404 |
PBJRateLimitError | Final 429 response |
PBJNetworkError | Fetch or transport failure |
PBJTimeoutError | Request deadline expires |
PBJAbortError | Caller 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.
