Skip to main content

ClientError

Thrown by HttpRequestObservable when the server responds with a 4xx or 5xx HTTP status. If the response body is an OPRA-formatted error (application/opra-response+json), structured issue details are parsed and exposed on issues.


Class

class ClientError extends Error {
readonly status?: number;
readonly issues: ErrorIssue[];
readonly cause?: Error;
}

Constructor

new ClientError(
init: { message: string; issues?: ErrorIssue[]; status?: number },
cause?: Error,
)

Properties

PropertyTypeDescription
messagestringHuman-readable error message (defaults to "<status> <statusText>")
statusnumber | undefinedHTTP status code
issuesErrorIssue[]Structured issue list from the OPRA response body, if available
causeError | undefinedUnderlying network or parsing error

Example

import { ClientError } from '@opra/client';

try {
const order = await client.get<Order>('orders/123').getBody();
} catch (err) {
if (err instanceof ClientError) {
console.error('HTTP', err.status); // e.g. 404
for (const issue of err.issues) {
console.error(issue.message, issue.path);
}
}
}

See also