Skip to main content

Problem

Struct Problem 

Source
#[non_exhaustive]
pub struct Problem { pub type_uri: Box<str>, pub title: Box<str>, pub status: StatusCode, pub detail: Option<Box<str>>, pub instance: Option<Box<str>>, pub request_id: Option<Box<str>>, }
Expand description

An RFC 9457 problem detail: a machine-readable description of an error.

Construct one with a status helper (Problem::forbidden, Problem::unprocessable_entity, Problem::internal, …) and refine it with the builder methods. The transport renders it (seiva-http as application/problem+json); here it is transport-neutral data.

The string members are stored as Box<str> rather than String: a problem is built once and never mutated after construction, so the extra String capacity word buys nothing, and the smaller footprint keeps the whole value comfortably under clippy’s result_large_err threshold. That is why no crate returning Result<_, Problem> needs to silence that lint.

#[non_exhaustive]: build one through the status helpers (Problem::forbidden, …) and the builder methods, never by field literal, so new RFC 9457 members are a non-breaking addition.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§type_uri: Box<str>

A URI reference identifying the problem type. Defaults to about:blank, which RFC 9457 treats as “no extra semantics beyond the status code”.

§title: Box<str>

A short, human-readable summary of the problem type.

§status: StatusCode

The HTTP status code.

§detail: Option<Box<str>>

A human-readable explanation specific to this occurrence.

§instance: Option<Box<str>>

A URI reference identifying this specific occurrence (e.g. the path).

§request_id: Option<Box<str>>

The id of the request that produced the problem, for correlation.

Implementations§

Source§

impl Problem

Source

pub fn new(status: StatusCode, title: impl Into<String>) -> Problem

A problem with the given status and title, type defaulting to about:blank and no detail/instance/request id yet.

Source

pub fn unauthorized(detail: impl Into<String>) -> Problem

A 401 Unauthorized problem (the caller presented a bearer credential that did not authenticate). The caller adds the WWW-Authenticate header.

Source

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

A 403 Forbidden problem (the permission guard denied the caller).

Source

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

A 404 Not Found problem.

Source

pub fn unprocessable_entity(detail: impl Into<String>) -> Problem

A 422 Unprocessable Entity problem (the body failed to parse or validate).

Source

pub fn too_many_requests(detail: impl Into<String>) -> Problem

A 429 Too Many Requests problem (the caller exceeded a rate limit). The caller adds a Retry-After header separately.

Source

pub fn internal(detail: impl Into<String>) -> Problem

A 500 Internal Server Error problem.

Source

pub fn with_type(self, type_uri: impl Into<String>) -> Problem

Sets the type URI.

Source

pub fn with_detail(self, detail: impl Into<String>) -> Problem

Sets the human-readable detail.

Source

pub fn with_instance(self, instance: impl Into<String>) -> Problem

Sets the instance URI reference.

Source

pub fn with_request_id(self, request_id: impl Into<String>) -> Problem

Sets the correlation request_id.

Source

pub fn with_request_id_opt(self, request_id: Option<String>) -> Problem

Sets the request_id when one is present, leaving it unset otherwise.

Source

pub fn to_json(&self) -> Value

The problem document as a JSON value, omitting absent optional members. The transport serialises this (e.g. as application/problem+json).

Trait Implementations§

Source§

impl Clone for Problem

Source§

fn clone(&self) -> Problem

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 Problem

Source§

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

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

impl Display for Problem

Source§

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

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

impl Error for Problem

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Box<dyn Error + Send + Sync>> for Problem

Maps the framework’s opaque port error into a problem.

A port error that is already a client-facing Problem is recovered verbatim, status and all: a pipeline behavior or handler that returned a Problem boxed as the port’s BoxError (a 403 from an authorize behavior, a 409 from an idempotency behavior) keeps its status instead of being flattened to 500. Only an explicitly-constructed Problem matches this path — an opaque adapter/database error does not downcast and maps to 500.

For every other error the internal Display is not sent to the client by default: it is logged server-side (correlate via the response’s request_id) and the client receives a generic detail, so an adapter/database message never leaks (OWASP API8). Setting SEIVA_EXPOSE_ERROR_DETAILS (development only) flips set_expose_error_details and the real text is surfaced.

Source§

fn from(error: Box<dyn Error + Send + Sync>) -> Problem

Converts to this type from the input type.
Source§

impl From<Problem> for ProblemResponse

Source§

fn from(problem: Problem) -> Self

Converts to this type from the input type.

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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
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