#[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
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: StatusCodeThe 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
impl Problem
Sourcepub fn new(status: StatusCode, title: impl Into<String>) -> Problem
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.
A 401 Unauthorized problem (the caller presented a bearer credential that
did not authenticate). The caller adds the WWW-Authenticate header.
Sourcepub fn forbidden(detail: impl Into<String>) -> Problem
pub fn forbidden(detail: impl Into<String>) -> Problem
A 403 Forbidden problem (the permission guard denied the caller).
Sourcepub fn unprocessable_entity(detail: impl Into<String>) -> Problem
pub fn unprocessable_entity(detail: impl Into<String>) -> Problem
A 422 Unprocessable Entity problem (the body failed to parse or validate).
Sourcepub fn too_many_requests(detail: impl Into<String>) -> Problem
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.
Sourcepub fn with_detail(self, detail: impl Into<String>) -> Problem
pub fn with_detail(self, detail: impl Into<String>) -> Problem
Sets the human-readable detail.
Sourcepub fn with_instance(self, instance: impl Into<String>) -> Problem
pub fn with_instance(self, instance: impl Into<String>) -> Problem
Sets the instance URI reference.
Sourcepub fn with_request_id(self, request_id: impl Into<String>) -> Problem
pub fn with_request_id(self, request_id: impl Into<String>) -> Problem
Sets the correlation request_id.
Sourcepub fn with_request_id_opt(self, request_id: Option<String>) -> Problem
pub fn with_request_id_opt(self, request_id: Option<String>) -> Problem
Sets the request_id when one is present, leaving it unset otherwise.
Trait Implementations§
Source§impl Error for Problem
impl Error for Problem
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<Box<dyn Error + Send + Sync>> for Problem
Maps the framework’s opaque port error into a problem.
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.