Skip to main content

jsonapi_error

Macro jsonapi_error 

Source
macro_rules! jsonapi_error {
    ($ctx:expr, $code:expr $(,)?) => { ... };
    ($ctx:expr, $code:expr, $detail:expr $(,)?) => { ... };
    ($ctx:expr, $code:expr, $detail:expr, attribute: $field:expr $(,)?) => { ... };
    ($ctx:expr, $code:expr, $detail:expr, pointer: $pointer:expr $(,)?) => { ... };
    ($ctx:expr, $code:expr, $detail:expr, parameter: $param:expr $(,)?) => { ... };
}
Expand description

Build a JsonApiError of any code, in a request’s context.

The general form the named shortcuts below are written in terms of. The context comes first because every error should carry the correlation id — that is what makes “here is my error id” resolvable in the audit log, and threading it here means it cannot be forgotten at a call site.

// A bare code:
let err = ash_jsonapi::jsonapi_error!(ctx, ErrorCode::Conflict);

// With client-facing detail:
let err = ash_jsonapi::jsonapi_error!(ctx, ErrorCode::Conflict, "the row moved under you");

// Pointing at an attribute, or a query parameter:
let err = ash_jsonapi::jsonapi_error!(ctx, ErrorCode::InvalidAttribute, "too long", attribute: "message");
let err = ash_jsonapi::jsonapi_error!(ctx, ErrorCode::InvalidParameter, "unknown field", parameter: "sort");