Skip to main content

DomainError

Trait DomainError 

Source
pub trait DomainError: Error {
    // Required methods
    fn category(&self) -> ErrorCategory;
    fn code(&self) -> ErrorCode;

    // Provided methods
    fn is_retryable(&self) -> bool { ... }
    fn http_status(&self) -> u16 { ... }
}
Expand description

The contract every klauthed error type implements.

Concrete error enums stay in their own crates and implement this to plug into shared handling (HTTP mapping, retry decisions, structured logging). The category() answer supplies sensible defaults for is_retryable and http_status, so most impls only define category and code.

Required Methods§

Source

fn category(&self) -> ErrorCategory

The coarse classification of this error.

Source

fn code(&self) -> ErrorCode

The stable domain.reason code for this error.

Provided Methods§

Source

fn is_retryable(&self) -> bool

Whether retrying might help. Defaults to the category’s policy.

Examples found in repository?
examples/error_kernel.rs (line 55)
45fn main() {
46    let errors = [OrderError::NotFound, OrderError::PaymentDeclined, OrderError::LedgerUnavailable];
47
48    println!("{:<32} {:<28} {:>4}  retryable", "error", "code", "http");
49    for err in &errors {
50        let code = err.code();
51        println!(
52            "{err:<32} {:<28} {:>4}  {}",
53            code.as_str(),
54            err.http_status(),
55            err.is_retryable(),
56        );
57    }
58}
Source

fn http_status(&self) -> u16

The HTTP status to surface. Defaults to the category’s status.

Examples found in repository?
examples/error_kernel.rs (line 54)
45fn main() {
46    let errors = [OrderError::NotFound, OrderError::PaymentDeclined, OrderError::LedgerUnavailable];
47
48    println!("{:<32} {:<28} {:>4}  retryable", "error", "code", "http");
49    for err in &errors {
50        let code = err.code();
51        println!(
52            "{err:<32} {:<28} {:>4}  {}",
53            code.as_str(),
54            err.http_status(),
55            err.is_retryable(),
56        );
57    }
58}

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§