Skip to main content

JsonApiError

Struct JsonApiError 

Source
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

Source

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.

Source

pub fn from_api_errors(errors: impl IntoIterator<Item = ApiError>) -> Self

Build from one or more ApiErrors.

Source

pub fn from_api_error(error: ApiError) -> Self

Build from a single ApiError.

Source

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).

Source

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.

Source

pub fn not_found(detail: impl Into<String>) -> Self

Build a 404 Not Found JSON:API error with a human-readable detail.

Source

pub fn forbidden(detail: impl Into<String>) -> Self

Build a 403 Forbidden JSON:API error with a human-readable detail.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> JsonApiError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JsonApiError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ApiErrors> for JsonApiError

Source§

fn from(errors: ApiErrors) -> Self

Converts to this type from the input type.
Source§

impl From<Box<ApiError>> for JsonApiError

Source§

fn from(error: Box<ApiError>) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for JsonApiError

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl IntoResponse for JsonApiError

Source§

fn into_response(self) -> Response

Create a response.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T, S> Handler<IntoResponseHandler, S> for T
where T: IntoResponse + Clone + Send + Sync + 'static,

Source§

type Future = Ready<Response<Body>>

The type of future calling this handler returns.
Source§

fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future

Call the handler with the given request.
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>>,

Apply a tower::Layer to the handler. Read more
Source§

fn with_state(self, state: S) -> HandlerService<Self, T, S>

Convert the handler into a Service by providing the state
Source§

impl<H, T> HandlerWithoutStateExt<T> for H
where H: Handler<T, ()>,

Source§

fn into_service(self) -> HandlerService<H, T, ()>

Convert the handler into a Service and no state.
Source§

fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>

Convert the handler into a MakeService and no state. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.