Derive Macro error_info_macros::ErrorInfo
source · #[derive(ErrorInfo)]
{
// Attributes available to this derive:
#[error]
}
Expand description
Derives the ErrorInfo trait for an enum.
It’s highly recommended to include a prefix on each variant, as the name is used to generate the code, which is
ofter required to be unique.
Each variant must provide an status and a message, which can use variant’s fields.
It requires the linkme crate to be available.
Examples
ⓘ
#[derive(Debug, ErrorInfo)]
#[allow(clippy::enum_variant_names)]
pub enum CustomErrorCode {
#[error(status = StatusCode::BAD_REQUEST, message = "Bad request: missing '{field}' field")]
BadRequest { field: String },
#[error(status = StatusCode::INTERNAL_SERVER_ERROR, message = "Internal server error")]
InternalServerError,
}