Lets the client tell success from failure the same way for every JSON endpoint, through the envelope they all answer with. It also defines Wire, the form a type takes once it has crossed JSON. The routes build the envelope, and the frontend's API helpers unwrap it.

Interfaces

I
APIError

Sent in an APIFailure. The frontend shows message to the user, so it is written for them.

I
APIFailure

Sent by the error middleware when a request fails, and by the few routes that answer an error themselves.

I
APISuccess

Sent by a route that succeeded, around its payload.

I
PaginatedData

Returned by the list endpoints, as the data of an APISuccess.

Type Aliases

T
APIResponse<T> = APISuccess<T> | APIFailure

Returned by every JSON endpoint. A reader tells the two apart by success.

T
Wire<T> = T extends Date ? string : T extends readonly (infer U)[] ? Wire<U>[] : T extends object ? [K in keyof T]: Wire<T[K]> : T

T as the client reads it from JSON, over HTTP, the socket or localStorage, where every Date has become an ISO string.

Variables

v
T
APIErrorCode: { BAD_REQUEST: string; UNAUTHORIZED: string; FORBIDDEN: string; NOT_FOUND: string; CONFLICT: string; RATE_LIMITED: string; SERVER_ERROR: string; BAD_GATEWAY: string; }

Lists the codes an APIError carries, one per HTTP status. The backend's APIException derives its code from the status it is given, and the frontend shows the message without reading the code.