Skip to main content

Class: APIError

Defined in: web/lib/errors.ts:168

API request error.

Remarks​

Thrown when an API request fails. Used in frontend code when fetching data from backend endpoints. Captures HTTP status code and endpoint information for debugging.

Example​

const response = await fetch('/api/eprints');
if (!response.ok) {
throw new APIError(
`Failed to fetch eprints: ${response.statusText}`,
response.status,
'/api/eprints'
);
}

Extends​

Constructors​

new APIError()​

new APIError(message, statusCode?, endpoint?, cause?): APIError

Defined in: web/lib/errors.ts:189

Creates a new APIError.

Parameters​

message​

string

Description of the API failure

statusCode?​

number

HTTP status code (e.g., 404, 500)

endpoint?​

string

API endpoint that failed (e.g., '/api/eprints')

cause?​

Error

Original error (if chained)

Returns​

APIError

Overrides​

ChiveError.constructor

Properties​

cause?​

readonly optional cause: Error

Defined in: web/lib/errors.ts:76

Original error that caused this error (if any).

Remarks​

Error chaining allows tracking the full error context through multiple layers of the application. Useful for debugging complex error scenarios.

Inherited from​

ChiveError.cause


code​

readonly code: "API_ERROR" = 'API_ERROR'

Defined in: web/lib/errors.ts:169

Machine-readable error code.

Remarks​

Error codes are unique identifiers for error types, enabling programmatic error handling (switch statements, error maps), error tracking in monitoring systems, and client-side error translation (i18n).

Overrides​

ChiveError.code


endpoint?​

readonly optional endpoint: string

Defined in: web/lib/errors.ts:179

API endpoint that was called.


statusCode?​

readonly optional statusCode: number

Defined in: web/lib/errors.ts:174

HTTP status code from the failed request (if available).

Accessors​

isRetryable​

Get Signature​

get isRetryable(): boolean

Defined in: web/lib/errors.ts:201

Whether this error is retryable.

Remarks​

Override in subclasses to indicate whether the operation can be retried. Default is false (non-retryable).

Returns​

boolean

Overrides​

ChiveError.isRetryable


severity​

Get Signature​

get severity(): ErrorSeverity

Defined in: web/lib/errors.ts:195

Error severity for monitoring and alerting.

Remarks​

Override in subclasses to customize severity based on error type. Default is 'medium' for most errors.

Returns​

ErrorSeverity

Overrides​

ChiveError.severity

Methods​

toJSON()​

toJSON(): SerializedError

Defined in: web/lib/errors.ts:209

Converts error to a plain object for structured logging.

Returns​

SerializedError

Remarks​

Produces a JSON-serializable object with all error properties, including nested cause chains.

Overrides​

ChiveError.toJSON