#[domain_error]Expand description
Define a domain error with automatic HTTP response conversion
This macro automatically:
- Derives
DebugandClonefor the type - Implements
Display,Error, andHttpErrortraits - Implements
From<T> for FrameworkErrorfor seamless?usage
§Attributes
status: HTTP status code (default: 500)message: Error message for Display (default: struct name converted to sentence)
§Example
ⓘ
use ferro::domain_error;
#[domain_error(status = 404, message = "User not found")]
pub struct UserNotFoundError {
pub user_id: i32,
}
// Usage in controller - just use ? operator
pub async fn get_user(id: i32) -> Result<User, FrameworkError> {
users.find(id).ok_or(UserNotFoundError { user_id: id })?
}