pub trait ModuleError:
Error
+ Send
+ Sync
+ Debug {
// Required methods
fn error_code(&self) -> &str;
fn status_code(&self) -> u16;
fn user_message(&self) -> &str;
// Provided methods
fn is_retriable(&self) -> bool { ... }
fn is_loggable(&self) -> bool { ... }
fn category(&self) -> ErrorCategory { ... }
fn debug_context(&self) -> Option<String> { ... }
}Expand description
Unified error trait for Backbone modules.
Implementing this trait allows errors to be:
- Converted to consistent API responses
- Logged with proper context
- Categorized for monitoring and alerting
Required Methods§
Sourcefn error_code(&self) -> &str
fn error_code(&self) -> &str
Machine-readable error code.
Format: {ENTITY}_{ERROR_TYPE} (e.g., USER_NOT_FOUND)
Sourcefn status_code(&self) -> u16
fn status_code(&self) -> u16
HTTP status code for this error.
Common codes:
- 400: Bad Request (validation errors)
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 409: Conflict (duplicate, version mismatch)
- 422: Unprocessable Entity
- 500: Internal Server Error
Sourcefn user_message(&self) -> &str
fn user_message(&self) -> &str
User-friendly error message.
This message is safe to display to end users. Avoid including sensitive information.
Provided Methods§
Sourcefn is_retriable(&self) -> bool
fn is_retriable(&self) -> bool
Whether this error is retriable.
Returns true for transient errors like timeouts
or temporary service unavailability.
Sourcefn is_loggable(&self) -> bool
fn is_loggable(&self) -> bool
Whether this error should be logged at error level.
Returns true for unexpected errors (500s).
Returns false for expected errors (4xx).
Sourcefn category(&self) -> ErrorCategory
fn category(&self) -> ErrorCategory
Error category for monitoring.
Sourcefn debug_context(&self) -> Option<String>
fn debug_context(&self) -> Option<String>
Additional context for debugging.
This information is logged but not exposed to users.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".