pub struct Problem {
pub problem_type: Option<String>,
pub title: String,
pub status: u16,
pub detail: Option<String>,
pub instance: Option<String>,
pub extensions: Map<String, Value>,
}Expand description
An RFC 9457 problem details response.
Serializes to application/problem+json with the correct HTTP status code.
Extension members (RFC 9457 §3.5) are serialized as top-level JSON fields
alongside the standard members.
§Manual construction
use axum_problem::Problem;
use serde_json::json;
let p = Problem::new(422)
.title("Validation Failed")
.detail("One or more fields are invalid")
.extension("violations", json!([
{"field": "email", "message": "must be a valid email"},
{"field": "age", "message": "must be at least 18"},
]));Produces:
{
"title": "Validation Failed",
"status": 422,
"detail": "One or more fields are invalid",
"violations": [...]
}Fields§
§problem_type: Option<String>URI reference identifying the problem type. Defaults to "about:blank".
title: StringShort human-readable summary of the problem type.
status: u16HTTP status code.
detail: Option<String>Human-readable explanation specific to this occurrence.
instance: Option<String>URI identifying the specific occurrence of this problem.
extensions: Map<String, Value>RFC 9457 extension members — serialized as top-level JSON fields.
Use Problem::extension to add fields fluently.
Implementations§
Source§impl Problem
impl Problem
Sourcepub fn new(status: u16) -> Self
pub fn new(status: u16) -> Self
Create a new problem for the given HTTP status code. The title is set automatically from the status code.
Sourcepub fn extension(self, key: impl Into<String>, value: impl Into<Value>) -> Self
pub fn extension(self, key: impl Into<String>, value: impl Into<Value>) -> Self
Add an RFC 9457 extension member as a top-level JSON field.
use axum_problem::Problem;
use serde_json::json;
let p = Problem::new(422)
.extension("violations", json!([{"field":"email","message":"invalid"}]))
.extension("request_id", json!("req-abc-123"));Sourcepub fn problem_type(self, t: impl Into<String>) -> Self
pub fn problem_type(self, t: impl Into<String>) -> Self
Set the problem type URI (defaults to "about:blank" in the response).
Sourcepub fn detail(self, detail: impl Into<String>) -> Self
pub fn detail(self, detail: impl Into<String>) -> Self
Add a human-readable explanation for this specific occurrence.
Sourcepub fn instance(self, instance: impl Into<String>) -> Self
pub fn instance(self, instance: impl Into<String>) -> Self
Add a URI identifying this specific occurrence.
pub fn bad_request() -> Self
pub fn forbidden() -> Self
pub fn not_found() -> Self
pub fn method_not_allowed() -> Self
pub fn conflict() -> Self
pub fn unprocessable_entity() -> Self
pub fn too_many_requests() -> Self
pub fn internal_server_error() -> Self
pub fn not_implemented() -> Self
Trait Implementations§
Source§impl IntoResponse for Problem
impl IntoResponse for Problem
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl Freeze for Problem
impl RefUnwindSafe for Problem
impl Send for Problem
impl Sync for Problem
impl Unpin for Problem
impl UnsafeUnpin for Problem
impl UnwindSafe for Problem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
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>>,
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>>,
tower::Layer to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Service by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Service and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
MakeService and no state. Read more