Skip to main content

Module api_error

Module api_error 

Source
Expand description

One error for an HTTP answer that is not a success: what kind of failure it is, and the words the caller reads.

The kind decides the HTTP status. The words are for the agent or person who reads them and decide nothing: a refusal may keep its FORBIDDEN: prefix because callers know it, not because anything reads it. Code that knows why it fails says so (ApiError::refused, ApiError::not_found, ApiError::bad_request, ApiError::conflict, ApiError::internal).

Most of the service layer still returns a plain String. Such an error becomes an ApiError through From<String>, which reads the kind from the text as the routes always did (ErrorKind::of_text). tests/api_error_status_tests.rs pins the status of every message in use, so giving an error its kind where it is made cannot move a status unseen.

Structsยง

ApiError ๐Ÿ”’
An error an HTTP route answers with: {"error": message} under the status of its kind.

Enumsยง

ErrorKind ๐Ÿ”’
Why a request was not served.