pub struct ProblemDetails {
pub status: StatusCode,
pub title: String,
pub detail: Option<String>,
pub extra: Box<Map<String, Value>>,
}Expand description
Structured error response shaped like an RFC 7807 Problem Details document, plus arbitrary extension members that get serialized into the JSON body.
Use this when one of the simple WebError::* variants doesn’t carry
enough information (e.g., a validation failure that wants to name
the failing field and rule).
return Err(WebError::Problem(
ProblemDetails::new(StatusCode::CONFLICT, "Validation")
.detail("title is required")
.extra("field", "data.title")
.extra("rule", "required"),
));Wire shape (application/problem+json):
{ "status": 409, "title": "Validation", "detail": "title is required",
"field": "data.title", "rule": "required" }Fields§
§status: StatusCodeThe HTTP status code, serialized as the status member.
title: StringA short, human-readable summary, serialized as the title member.
detail: Option<String>An optional longer explanation, serialized as the detail member.
extra: Box<Map<String, Value>>Extension members. Serialized alongside status / title / detail.
Keys that collide with the standard members are ignored.
Boxed to keep WebError small: this map dominates the struct’s size,
yet extensions are optional and most errors carry none — so the common
case pays one pointer, not a full inline map, on every Result return.
Implementations§
Source§impl ProblemDetails
impl ProblemDetails
Sourcepub fn new(status: StatusCode, title: impl Into<String>) -> ProblemDetails
pub fn new(status: StatusCode, title: impl Into<String>) -> ProblemDetails
Construct a new problem with the given status code and title.
Sourcepub fn detail(self, detail: impl Into<String>) -> ProblemDetails
pub fn detail(self, detail: impl Into<String>) -> ProblemDetails
Set the human-readable detail message.
Trait Implementations§
Source§impl Clone for ProblemDetails
impl Clone for ProblemDetails
Source§fn clone(&self) -> ProblemDetails
fn clone(&self) -> ProblemDetails
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more