pub struct JsonApiError { /* private fields */ }Expand description
A JSON:API error response, usable both as an axum extractor Rejection and
as an IntoResponse error returned from a handler.
Implementations§
Source§impl JsonApiError
impl JsonApiError
Sourcepub fn from_core(error: &Error) -> Self
pub fn from_core(error: &Error) -> Self
Build from a jsonapi_core::Error, mapping it to the correct status and
a JSON:API error document.
Sourcepub fn from_api_errors(errors: impl IntoIterator<Item = ApiError>) -> Self
pub fn from_api_errors(errors: impl IntoIterator<Item = ApiError>) -> Self
Build from one or more ApiErrors.
Sourcepub fn from_api_error(error: ApiError) -> Self
pub fn from_api_error(error: ApiError) -> Self
Build from a single ApiError.
Sourcepub fn from_status(status: StatusCode, detail: Option<String>) -> Self
pub fn from_status(status: StatusCode, detail: Option<String>) -> Self
Build a JSON:API error response for a bare HTTP status (with optional
human-readable detail).
Used to re-shape errors that originate as a plain status rather than a
jsonapi_core::Error — e.g. an axum body-size-limit rejection (413)
or an unmatched-route fallback (404).
Sourcepub fn conflict(detail: impl Into<String>) -> Self
pub fn conflict(detail: impl Into<String>) -> Self
Build a 409 Conflict JSON:API error for an id collision (a chosen id
that already exists), with source.pointer /data/id. Collision
detection is the application’s job; this produces the error to return.
Sourcepub fn not_found(detail: impl Into<String>) -> Self
pub fn not_found(detail: impl Into<String>) -> Self
Build a 404 Not Found JSON:API error with a human-readable detail.
Sourcepub fn forbidden(detail: impl Into<String>) -> Self
pub fn forbidden(detail: impl Into<String>) -> Self
Build a 403 Forbidden JSON:API error with a human-readable detail.
Sourcepub fn unprocessable(detail: impl Into<String>) -> Self
pub fn unprocessable(detail: impl Into<String>) -> Self
Build a 422 Unprocessable Entity JSON:API error with a human-readable
detail — for a well-formed request that fails semantic validation.
Sourcepub fn unprocessable_with_pointer(
pointer: impl Into<String>,
detail: impl Into<String>,
) -> Self
pub fn unprocessable_with_pointer( pointer: impl Into<String>, detail: impl Into<String>, ) -> Self
Build a 422 Unprocessable Entity error carrying both a detail and a
source.pointer (an RFC 6901 JSON pointer to the offending member, e.g.
/data/relationships/author) — the common shape for a failed
attribute/relationship validation.
Sourcepub fn internal(detail: impl Into<String>) -> Self
pub fn internal(detail: impl Into<String>) -> Self
Build a 500 Internal Server Error JSON:API error.
The detail you pass is treated as internal, potentially sensitive text:
it is not placed in the response body unless the debug-errors
feature is enabled, so raw error strings never leak to clients by
default. Log the raw message in your application if you need it. The
response always carries the generic “Internal Server Error” title and no
detail.
Trait Implementations§
Source§impl Clone for JsonApiError
impl Clone for JsonApiError
Source§fn clone(&self) -> JsonApiError
fn clone(&self) -> JsonApiError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for JsonApiError
impl Debug for JsonApiError
Source§impl From<ApiErrors> for JsonApiError
impl From<ApiErrors> for JsonApiError
Source§impl From<Error> for JsonApiError
impl From<Error> for JsonApiError
Source§impl IntoResponse for JsonApiError
impl IntoResponse for JsonApiError
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl !RefUnwindSafe for JsonApiError
impl !UnwindSafe for JsonApiError
impl Freeze for JsonApiError
impl Send for JsonApiError
impl Sync for JsonApiError
impl Unpin for JsonApiError
impl UnsafeUnpin for JsonApiError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
Source§fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
tower::Layer to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Service by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Service and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
MakeService and no state. Read more