pub enum Error {
Show 48 variants
Http(String),
RouteNotFound(String),
MethodNotAllowed(String),
DependencyInjection(String),
ProviderNotFound(String),
Serialization(String),
Deserialization(String),
Validation(String),
Internal(String),
Forbidden(String),
Io(Error),
BadRequest(String),
Unauthorized(String),
PaymentRequired(String),
NotFound(String),
NotAcceptable(String),
ProxyAuthenticationRequired(String),
RequestTimeout(String),
Conflict(String),
Gone(String),
LengthRequired(String),
PreconditionFailed(String),
PayloadTooLarge(String),
UriTooLong(String),
UnsupportedMediaType(String),
RangeNotSatisfiable(String),
ExpectationFailed(String),
ImATeapot(String),
MisdirectedRequest(String),
UnprocessableEntity(String),
Locked(String),
FailedDependency(String),
TooEarly(String),
UpgradeRequired(String),
PreconditionRequired(String),
TooManyRequests(String),
RequestHeaderFieldsTooLarge(String),
UnavailableForLegalReasons(String),
NotImplemented(String),
BadGateway(String),
ServiceUnavailable(String),
GatewayTimeout(String),
HttpVersionNotSupported(String),
VariantAlsoNegotiates(String),
InsufficientStorage(String),
LoopDetected(String),
NotExtended(String),
NetworkAuthenticationRequired(String),
}Variants§
Http(String)
RouteNotFound(String)
MethodNotAllowed(String)
DependencyInjection(String)
ProviderNotFound(String)
Serialization(String)
Deserialization(String)
Validation(String)
Internal(String)
Forbidden(String)
Io(Error)
BadRequest(String)
PaymentRequired(String)
NotFound(String)
NotAcceptable(String)
ProxyAuthenticationRequired(String)
RequestTimeout(String)
Conflict(String)
Gone(String)
LengthRequired(String)
PreconditionFailed(String)
PayloadTooLarge(String)
UriTooLong(String)
UnsupportedMediaType(String)
RangeNotSatisfiable(String)
ExpectationFailed(String)
ImATeapot(String)
MisdirectedRequest(String)
UnprocessableEntity(String)
Locked(String)
FailedDependency(String)
TooEarly(String)
UpgradeRequired(String)
PreconditionRequired(String)
TooManyRequests(String)
RequestHeaderFieldsTooLarge(String)
NotImplemented(String)
BadGateway(String)
GatewayTimeout(String)
HttpVersionNotSupported(String)
VariantAlsoNegotiates(String)
InsufficientStorage(String)
LoopDetected(String)
NotExtended(String)
NetworkAuthenticationRequired(String)
Implementations§
Source§impl Error
impl Error
Sourcepub fn status_code(&self) -> u16
pub fn status_code(&self) -> u16
Get the HTTP status code for this error
Sourcepub fn http_status(&self) -> HttpStatus
pub fn http_status(&self) -> HttpStatus
Get the HttpStatus enum for this error
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Check if this is a client error (4xx)
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Check if this is a server error (5xx)
Sourcepub fn to_client_response(&self) -> HttpResponse
pub fn to_client_response(&self) -> HttpResponse
Build a client-safe HTTP response for this error.
The status code comes from Error::status_code. 4xx client errors
keep their descriptive message so callers can correct their request;
5xx server errors are redacted to a generic "Internal Server Error"
message so internal detail (connection strings, upstream errors, stack
context) never leaks to the client. The full error should be logged
separately at the call site.
The JSON body is always {"error": <message>, "status": <code>}. This
is the single canonical error-to-response mapping shared by every server
transport (HTTP/1, HTTP/2, HTTP/3, and the micro server) so their error
responses never drift apart.
Sourcepub fn bad_request(msg: impl Into<String>) -> Self
pub fn bad_request(msg: impl Into<String>) -> Self
Create a bad request error with a message.
Create an unauthorized error with a message.
Sourcepub fn internal(msg: impl Into<String>) -> Self
pub fn internal(msg: impl Into<String>) -> Self
Create an internal server error with a message.
Sourcepub fn validation(msg: impl Into<String>) -> Self
pub fn validation(msg: impl Into<String>) -> Self
Create a validation error with a message.
Sourcepub fn rate_limited(msg: impl Into<String>) -> Self
pub fn rate_limited(msg: impl Into<String>) -> Self
Create a rate limit error with a message.
Create a service unavailable error with a message.
Trait Implementations§
Source§fn correlate(&self, context: CorrelationContext) -> CorrelatedError
fn correlate(&self, context: CorrelationContext) -> CorrelatedError
Source§fn correlate_with_request(&self, request: &HttpRequest) -> CorrelatedError
fn correlate_with_request(&self, request: &HttpRequest) -> CorrelatedError
Source§impl Error for Error
impl Error for Error
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()
Auto Trait Implementations§
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Freeze for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<R, D> DepsPresent<D> for R
Source§impl<T> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Provider for Twhere
T: Injectable,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more