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§
Sourcefn category(&self) -> ErrorCategory
fn category(&self) -> ErrorCategory
The coarse classification of this error.
Provided Methods§
Sourcefn is_retryable(&self) -> bool
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}Sourcefn http_status(&self) -> u16
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".