Expand description
RFC 9457 problem details for axum.
§Quick start
use axum::{Router, routing::get, extract::Path};
use axum_problem::{AxumProblem, Problem};
use thiserror::Error;
#[derive(Debug, Error, AxumProblem)]
pub enum ApiError {
#[error("order {id} not found")]
#[problem(status = 404)]
NotFound { id: i64 },
#[error("unauthorized")]
#[problem(status = 401)]
Unauthorized,
#[error("database error: {0}")]
#[problem(status = 500, mask)]
Database(String),
}
async fn get_order(Path(id): Path<i64>) -> Result<String, ApiError> {
Err(ApiError::NotFound { id })
}The mask attribute hides the error detail from the HTTP response (preventing
internal details leaking to clients) and logs the full error via tracing::error!.
Structs§
- Problem
- An RFC 9457 problem details response.
Functions§
- status_
title - Returns a short title for common HTTP status codes.
Derive Macros§
- Axum
Problem - Derive
IntoResponsefor an error enum, mapping each variant to an RFC 9457 problem details response.