Skip to main content

domain_error

Attribute Macro domain_error 

Source
#[domain_error]
Expand description

Define a domain error with automatic HTTP response conversion

This macro automatically:

  1. Derives Debug and Clone for the type
  2. Implements Display, Error, and HttpError traits
  3. Implements From<T> for FrameworkError for 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 })?
}