Skip to main content

ApiErrorBody

Struct ApiErrorBody 

Source
pub struct ApiErrorBody<E = Value> {
    pub message: String,
    pub status: u16,
    pub code: String,
    pub error: E,
}
Expand description

Envelope for HTTP error responses produced by #[derive(ApiError)].

The type parameter E determines the shape of the error field. When generated by the macro, E is the concrete error enum — giving frontends a fully typed payload. The default (serde_json::Value) is used by layer contributions and hand-rolled error responses where the concrete type is not known.

§Example

use doxa::ApiErrorBody;

let body: ApiErrorBody<()> =
    ApiErrorBody::new(404, "not_found", "widget 7 does not exist", ());
let json = serde_json::to_value(&body).unwrap();
assert_eq!(json["status"], 404);
assert_eq!(json["code"], "not_found");
assert_eq!(json["message"], "widget 7 does not exist");

Fields§

§message: String

Human-readable message from the source error’s Display impl.

§status: u16

HTTP status code, mirrored from the response status line.

§code: String

Application-level error code suitable for client-side discrimination (e.g. "not_found", "validation_error").

§error: E

Typed, machine-readable error data. When E is a concrete error enum, this field carries the enum’s serde serialization. When E is the default serde_json::Value, it accepts any JSON value.

Implementations§

Source§

impl<E: Serialize> ApiErrorBody<E>

Source

pub fn new( status: u16, code: impl Into<String>, message: impl Into<String>, error: E, ) -> Self

Construct an ApiErrorBody from its raw fields.

Most callers should let #[derive(ApiError)] build this for them; this constructor exists for hand-rolled error responses, layer contributions, and tests.

Trait Implementations§

Source§

impl<E: Clone> Clone for ApiErrorBody<E>

Source§

fn clone(&self) -> ApiErrorBody<E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<E> ComposeSchema for ApiErrorBody<E>
where E: ToSchema,

Source§

impl<E: Debug> Debug for ApiErrorBody<E>

Source§

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

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

impl<'de, E> Deserialize<'de> for ApiErrorBody<E>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<E> Serialize for ApiErrorBody<E>
where E: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<E> ToSchema for ApiErrorBody<E>
where E: ToSchema,

Source§

fn name() -> Cow<'static, str>

Return name of the schema. Read more
Source§

fn schemas(schemas: &mut Vec<(String, RefOr<Schema>)>)

Implement reference utoipa::openapi::schema::Schemas for this type. Read more

Auto Trait Implementations§

§

impl<E> Freeze for ApiErrorBody<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for ApiErrorBody<E>
where E: RefUnwindSafe,

§

impl<E> Send for ApiErrorBody<E>
where E: Send,

§

impl<E> Sync for ApiErrorBody<E>
where E: Sync,

§

impl<E> Unpin for ApiErrorBody<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for ApiErrorBody<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for ApiErrorBody<E>
where E: UnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. 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> PartialSchema for T
where T: ComposeSchema + ?Sized,

Source§

fn schema() -> RefOr<Schema>

Return ref or schema of implementing type that can then be used to construct combined schemas.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,