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
| Property | Type | Description |
|---|---|---|
message | string | Human-readable error message (defaults to "<status> <statusText>") |
status | number | undefined | HTTP status code |
issues | ErrorIssue[] | Structured issue list from the OPRA response body, if available |
cause | Error | undefined | Underlying 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
HttpRequestObservable— whereClientErroris thrown