pub enum WebError {
InvalidRequest {
message: String,
},
Unauthorized {
reason: String,
},
Forbidden {
reason: String,
},
NotFound {
resource: String,
},
ContentTooLarge {
size: usize,
max: usize,
},
RateLimited {
retry_after_secs: u64,
},
ProcessingError(String),
InternalError {
message: String,
},
ServiceUnavailable {
reason: String,
},
GatewayTimeout {
timeout_ms: u64,
},
}Expand description
HTTP-level error with status codes and structured JSON responses.
This error type is designed for web API responses, providing:
- Appropriate HTTP status codes
- Structured JSON error bodies
- Request ID correlation for tracing
- Logging integration
§JSON Response Format
{
"error": "Human-readable error message",
"code": "ERROR_CODE",
"request_id": "optional-request-id"
}Variants§
InvalidRequest
Invalid request - malformed input, missing fields, validation failures HTTP Status: 400 Bad Request
Unauthorized - authentication required or invalid credentials HTTP Status: 401 Unauthorized
Fields
Reason for authorization failure
Forbidden
Forbidden - authenticated but not permitted HTTP Status: 403 Forbidden
NotFound
Resource not found HTTP Status: 404 Not Found
ContentTooLarge
Request content too large HTTP Status: 413 Payload Too Large
RateLimited
Rate limit exceeded HTTP Status: 429 Too Many Requests
ProcessingError(String)
Processing error - operation failed during execution HTTP Status: 500 Internal Server Error
InternalError
Internal server error - unexpected failures HTTP Status: 500 Internal Server Error
Service unavailable - temporarily unable to handle request HTTP Status: 503 Service Unavailable
GatewayTimeout
Gateway timeout - upstream service timed out HTTP Status: 504 Gateway Timeout
Implementations§
Source§impl WebError
impl WebError
Sourcepub fn invalid_request(message: impl Into<String>) -> Self
pub fn invalid_request(message: impl Into<String>) -> Self
Create an invalid request error with a message
Sourcepub fn missing_field(field: &str) -> Self
pub fn missing_field(field: &str) -> Self
Create an invalid request error for a missing field
Sourcepub fn invalid_field(field: &str, reason: &str) -> Self
pub fn invalid_field(field: &str, reason: &str) -> Self
Create an invalid request error for an invalid field value
Create an unauthorized error
Sourcepub fn content_too_large(size: usize, max: usize) -> Self
pub fn content_too_large(size: usize, max: usize) -> Self
Create a content too large error
Sourcepub fn rate_limited(retry_after_secs: u64) -> Self
pub fn rate_limited(retry_after_secs: u64) -> Self
Create a rate limited error
Sourcepub fn processing<E: Display>(source: E) -> Self
pub fn processing<E: Display>(source: E) -> Self
Create a processing error from any error type
Sourcepub fn internal_from<E: Error>(err: E) -> Self
pub fn internal_from<E: Error>(err: E) -> Self
Create an internal error from any error, sanitizing the message
Create a service unavailable error
Sourcepub fn gateway_timeout(timeout_ms: u64) -> Self
pub fn gateway_timeout(timeout_ms: u64) -> Self
Create a gateway timeout error
Sourcepub fn status_code(&self) -> u16
pub fn status_code(&self) -> u16
Get the HTTP status code for this error
Sourcepub fn error_code(&self) -> &'static str
pub fn error_code(&self) -> &'static str
Get the error code string for this error
Sourcepub fn to_json_with_request_id(&self, request_id: &str) -> Value
pub fn to_json_with_request_id(&self, request_id: &str) -> Value
Convert error to JSON response body with request ID
Sourcepub fn log(&self, request_id: Option<&str>)
pub fn log(&self, request_id: Option<&str>)
Log the error with appropriate level and optional request ID
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Check if this error should be retried
Sourcepub fn retry_after(&self) -> Option<u64>
pub fn retry_after(&self) -> Option<u64>
Get retry-after header value if applicable
Trait Implementations§
Source§impl Error for WebError
impl Error for WebError
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
Source§impl From<&WebError> for ErrorResponse
impl From<&WebError> for ErrorResponse
Auto Trait Implementations§
impl Freeze for WebError
impl RefUnwindSafe for WebError
impl Send for WebError
impl Sync for WebError
impl Unpin for WebError
impl UnwindSafe for WebError
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> 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>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.