Expand description
Call-site conveniences: the one-liners a handler is mostly made of.
Everything here is sugar over JsonApiError,
api! and axum — there is no behaviour in this module that
is not reachable by writing the long form, and the long form stays the
documented one. What these buy is that the short form is also the
correct one: an error built by hand is one forgotten .in_context(ctx)
away from an error the audit log cannot resolve, and a router assembled by
hand is one forgotten layer() away from a service where
every request is a 500.
§Errors
jsonapi_error! builds any code, and the named
shortcuts cover the ones a handler actually reaches for:
// Long form:
let err = JsonApiError::in_request(ErrorCode::NotFound, &ctx)
.detail("no such todo");
// Short form — the same error, with the context threaded for you:
let err = ash_jsonapi::not_found!(ctx, "no such todo");
// Pointing at the member at fault:
let err = ash_jsonapi::invalid_attribute!(ctx, "must not be empty", field);§Guards
ensure! is the rpc_validate! of this crate: a
precondition that returns a JSON:API error rather than panicking, so a
handler reads as its rules.
fn check(message: &str, ctx: &Context) -> Result<(), JsonApiError> {
ash_jsonapi::ensure!(!message.is_empty(), ctx, "message must not be empty", "message");
Ok(())
}Functions§
- shutdown_
signal http - Resolve when the process is asked to stop:
Ctrl-C, orSIGTERM.