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.
Sent in an APIFailure. The frontend shows message to the user, so
it is written for them.
Sent by the error middleware when a request fails, and by the few routes that answer an error themselves.
Returned by the list endpoints, as the data of an APISuccess.
- hasMore: boolean
- items: T[]
-
total: number
The size of the whole list, set only by search, which shows it.
Returned by every JSON endpoint. A reader tells the two apart by success.
T as the client reads it from JSON, over HTTP, the socket or
localStorage, where every Date has become an ISO 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.
-
BAD_GATEWAY: string
Answers when another site, such as Bandcamp or YouTube, failed us.
- BAD_REQUEST: string
- CONFLICT: string
- FORBIDDEN: string
-
NOT_FOUND: string
Also answers for what exists but the caller may not see.
- RATE_LIMITED: string
- SERVER_ERROR: string
- UNAUTHORIZED: string
Usage
import * as mod from "shared/api.ts";