macro_rules! define_domain_errors {
(
domain: $domain:literal,
prefix: $prefix:expr,
errors: {
$( $variant:ident => ($index:expr, $status:expr, $display:literal) ),* $(,)?
}
) => { ... };
}Expand description
Macro to define domain-specific error codes with minimal boilerplate.
§Example
ⓘ
use cqrs_rust_lib::define_domain_errors;
use http::StatusCode;
define_domain_errors! {
domain: "tenant",
prefix: 4,
errors: {
NotFound => (1, StatusCode::NOT_FOUND, "NOT_FOUND"),
Suspended => (2, StatusCode::BAD_REQUEST, "SUSPENDED"),
Deleted => (3, StatusCode::GONE, "DELETED"),
SlugExists => (4, StatusCode::CONFLICT, "SLUG_EXISTS"),
}
}
// Usage:
let err = ErrorCode::NotFound.error("Tenant 'abc' not found");
// -> CqrsError { domain: "tenant", code: "TENANT_NOT_FOUND", internal_code: 4001, ... }