Skip to main content

Class: APIError

Defined in: src/types/errors.ts:610

API request error.

Remarks​

Thrown when an API request fails. Used primarily 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: src/types/errors.ts:631

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: src/types/errors.ts:71

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.

Example​

try {
await fetchData();
} catch (err) {
throw new ValidationError('Failed to validate data', 'field', 'required', err as Error);
}

Inherited from​

ChiveError.cause


code​

readonly code: "API_ERROR" = 'API_ERROR'

Defined in: src/types/errors.ts:611

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: src/types/errors.ts:621

API endpoint that was called.


statusCode?​

readonly optional statusCode: number

Defined in: src/types/errors.ts:616

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