Skip to main content
A call can fail in three ways:
  • API error: the API answered with an error status, such as 404 or 422. The body is a problem document with a code, a title, the status, and usually a detail and a requestId.
  • Transport error: no response arrived, because of a network failure or a timeout.
  • Response error: a successful response that the client could not read as the contract describes, for example a status the contract does not list or a body of the wrong shape.
Before an error reaches you, the client retries the requests it can retry. See Retries and timeouts.

Error types

Every error the client throws extends PhotonError, which has operationId and requestId when they are known.error.body is typed unknown: the client does not check error bodies against the contract. The contract’s error types are exported for reference, per operation, such as GetProjectErrors.

Handle an API error

Match on the problem’s code (or its type URI). Both are stable. Do not match on title or detail: they are written for people and can change. Every code is listed in the problem catalog. This example asks for a project that does not exist, so the API answers 404 with PROJECT_NOT_FOUND:

Request IDs

Every API response has an X-Request-ID header that identifies that HTTP attempt, and problem documents usually repeat it as requestId. Log it, and quote it when you contact Photon support about a failed call. When the client retried a call, the request ID is the one from the last attempt.
  • TypeScript: error.requestId on ApiError and ResponseValidationError.
  • Python: error.request_id on ApiError and ResponseValidationError.
  • Rust: response.headers().get("x-request-id") on the ResponseValue in Error::Api, headers in Error::UnexpectedStatus and Error::Decode, or the problem’s request_id field.
For successful calls, read the request ID from the raw response.