WebError

Enum WebError 

Source
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

Fields

§message: String

Detailed error message

§

Unauthorized

Unauthorized - authentication required or invalid credentials HTTP Status: 401 Unauthorized

Fields

§reason: String

Reason for authorization failure

§

Forbidden

Forbidden - authenticated but not permitted HTTP Status: 403 Forbidden

Fields

§reason: String

Reason access was denied

§

NotFound

Resource not found HTTP Status: 404 Not Found

Fields

§resource: String

Description of the missing resource

§

ContentTooLarge

Request content too large HTTP Status: 413 Payload Too Large

Fields

§size: usize

Actual size of the content

§max: usize

Maximum allowed size

§

RateLimited

Rate limit exceeded HTTP Status: 429 Too Many Requests

Fields

§retry_after_secs: u64

Number of seconds to wait before retrying

§

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

Fields

§message: String

Error message (sanitized for external display)

§

ServiceUnavailable

Service unavailable - temporarily unable to handle request HTTP Status: 503 Service Unavailable

Fields

§reason: String

Reason the service is unavailable

§

GatewayTimeout

Gateway timeout - upstream service timed out HTTP Status: 504 Gateway Timeout

Fields

§timeout_ms: u64

Timeout duration in milliseconds

Implementations§

Source§

impl WebError

Source

pub fn invalid_request(message: impl Into<String>) -> Self

Create an invalid request error with a message

Source

pub fn missing_field(field: &str) -> Self

Create an invalid request error for a missing field

Source

pub fn invalid_field(field: &str, reason: &str) -> Self

Create an invalid request error for an invalid field value

Source

pub fn unauthorized(reason: impl Into<String>) -> Self

Create an unauthorized error

Source

pub fn forbidden(reason: impl Into<String>) -> Self

Create a forbidden error

Source

pub fn not_found(resource: impl Into<String>) -> Self

Create a not found error

Source

pub fn content_too_large(size: usize, max: usize) -> Self

Create a content too large error

Source

pub fn rate_limited(retry_after_secs: u64) -> Self

Create a rate limited error

Source

pub fn processing<E: Display>(source: E) -> Self

Create a processing error from any error type

Source

pub fn internal(message: impl Into<String>) -> Self

Create an internal error with a message

Source

pub fn internal_from<E: Error>(err: E) -> Self

Create an internal error from any error, sanitizing the message

Source

pub fn service_unavailable(reason: impl Into<String>) -> Self

Create a service unavailable error

Source

pub fn gateway_timeout(timeout_ms: u64) -> Self

Create a gateway timeout error

Source

pub fn status_code(&self) -> u16

Get the HTTP status code for this error

Source

pub fn error_code(&self) -> &'static str

Get the error code string for this error

Source

pub fn to_json(&self) -> Value

Convert error to JSON response body

Source

pub fn to_json_with_request_id(&self, request_id: &str) -> Value

Convert error to JSON response body with request ID

Source

pub fn log(&self, request_id: Option<&str>)

Log the error with appropriate level and optional request ID

Source

pub fn is_retryable(&self) -> bool

Check if this error should be retried

Source

pub fn retry_after(&self) -> Option<u64>

Get retry-after header value if applicable

Trait Implementations§

Source§

impl Clone for WebError

Source§

fn clone(&self) -> WebError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WebError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for WebError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for WebError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<&WebError> for ErrorResponse

Source§

fn from(err: &WebError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for WebError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for WebError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for WebError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<WebError> for Error

Source§

fn from(source: WebError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more