Skip to main content

Module error

Module error 

Source
Expand description

A machine-readable error body for the v2 API.

Every failure used to be a bare (StatusCode, &'static str), which axum renders as text/plain. On an API whose success path is JSON that is a trap: a client’s await res.json() throws a SyntaxError on every failure, so the handler reports a parse problem instead of the 404 that actually happened. And two 404s were distinguishable only by their prose — "page not found" vs "menu not found" — so branching meant string-matching English.

Errors now carry the same envelope as everything else:

{ "error": { "code": "not_found", "message": "page not found" } }

code is the stable part. message is for humans and may be reworded; clients branch on code and on the HTTP status.

Structs§

ApiError
One API failure, rendered as JSON.

Enums§

ErrorCode
A stable, machine-readable error identifier.

Functions§

method_not_allowed_json
Give axum’s bodiless 405 the JSON envelope the rest of the API uses.