pub struct Problem {
pub slug: &'static str,
pub status: StatusCode,
pub title: &'static str,
pub detail: Option<String>,
pub instance: Option<String>,
/* private fields */
}Expand description
An API error, serialized as application/problem+json.
type is the venture’s stable slug URI (see
Problem::type_uri), instance is the request id, and the body
never leaks internals: 500s carry no stack, no source error, nothing
but the generic internal slug.
Fields§
§slug: &'static str§status: StatusCode§title: &'static str§detail: Option<String>§instance: Option<String>Implementations§
Source§impl Problem
impl Problem
pub fn new(def: &ProblemDef) -> Self
pub fn with_detail(self, detail: impl Into<String>) -> Self
Sourcepub fn with_extension(
self,
name: impl Into<String>,
value: impl Into<Value>,
) -> Self
pub fn with_extension( self, name: impl Into<String>, value: impl Into<Value>, ) -> Self
Adds an RFC 9457 §3.2 extension member to the body.
pub fn internal() -> Self
pub fn validation_failed(detail: impl Into<String>) -> Self
pub fn request_too_large() -> Self
pub fn not_ready(detail: impl Into<String>) -> Self
pub fn not_found() -> Self
Sourcepub fn type_uri(&self, base: &str) -> String
pub fn type_uri(&self, base: &str) -> String
The problem’s type URI: the venture’s base followed by the slug.
The base is the serving venture’s — crate::Venture::problem_type_base
— never a constant of this crate: every venture names its problems
under its own domain. A base of ABOUT_BLANK (the context-free
default, and a venture with no public URL) yields about:blank
itself: the slug has no URI to live under, and RFC 9457 §4.2.1
reserves exactly that value.
Sourcepub fn into_response_with_base(self, base: &str) -> Response
pub fn into_response_with_base(self, base: &str) -> Response
Renders this problem as a response whose type names base — the
serving venture’s crate::Venture::problem_type_base. For a
response built outside a harness router, where no layer stands
behind it to name the venture: a runtime’s pre-router short-circuit
(the native host refusal, the Worker’s body ceiling).
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<StreamError> for Problem
A mid-stream failure is a Problem: a ceiling breach is exactly the
413 request-too-large a buffered route answers with, and a transport
failure is a server-side fault the caller cannot fix, so it becomes the
generic 500 internal (the same mapping crate::ports::DbError gets —
no internals in the body, the error only logged).
impl From<StreamError> for Problem
A mid-stream failure is a Problem: a ceiling breach is exactly the
413 request-too-large a buffered route answers with, and a transport
failure is a server-side fault the caller cannot fix, so it becomes the
generic 500 internal (the same mapping crate::ports::DbError gets —
no internals in the body, the error only logged).
Source§fn from(error: StreamError) -> Self
fn from(error: StreamError) -> Self
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