Skip to main content

ApiError

Trait ApiError 

Source
pub trait ApiError: Display {
    // Required methods
    fn status_code(&self) -> StatusCode;
    fn error_code(&self) -> &'static str;

    // Provided method
    fn retry_after_secs(&self) -> Option<u64> { ... }
}
Expand description

Trait for application-specific error types that can be rendered as structured JSON error responses.

Each project defines its own error enum and implements this trait. The shared IntoResponse implementation (via into_error_response) handles JSON serialization, status codes, and the Retry-After header for rate-limited responses.

Required Methods§

Source

fn status_code(&self) -> StatusCode

HTTP status code for this error variant.

Source

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

Machine-readable error code string (e.g. "INVALID_DOMAIN").

Provided Methods§

Source

fn retry_after_secs(&self) -> Option<u64>

If this is a rate-limited error, return the retry-after duration in seconds.

Implementors§