#[derive(AxumProblem)]
{
// Attributes available to this derive:
#[problem]
}
Expand description
Derive IntoResponse for an error enum, mapping each variant to an
RFC 9457 problem details response.
§Attributes
Apply #[problem(...)] to each variant:
status = <u16>— required. The HTTP status code for this variant.title = "<str>"— Optional. Defaults to the standard title for the status code (e.g. 404 → “Not Found”).mask— Optional. Hides the error detail from the HTTP response and logs it instead. Use for 5xx errors where you don’t want internal details leaking to clients.log = "<level>"— Optional, only relevant whenmaskis set. Controls the tracing level used to log the masked error. One of"error"(default),"warn","info", or"debug".
§Example
ⓘ
use axum_problem::AxumProblem;
use thiserror::Error;
#[derive(Debug, Error, AxumProblem)]
pub enum ApiError {
#[error("order {id} not found")]
#[problem(status = 404)]
NotFound { id: i64 },
#[error("access denied")]
#[problem(status = 401)]
Unauthorized,
#[error("db error: {0}")]
#[problem(status = 500, mask)] // logs at error level (default)
Database(String),
#[error("rate limited: {0}")]
#[problem(status = 429, mask, log = "warn")] // logs at warn level
RateLimited(String),
}