Expand description
Standardized API error responses. See api_errors::ApiError.
Standardized API error responses.
All errors share a consistent JSON shape so frontends can parse them uniformly. Follows the RFC 7807 “Problem Details” convention loosely:
{
"error": "validation_failed",
"message": "title cannot be empty",
"status": 422,
"details": {"field": "title"}
}§Quick start
ⓘ
use rustango::api_errors::ApiError;
async fn create_post(body: Json<NewPost>) -> Result<Json<Post>, ApiError> {
if body.title.is_empty() {
return Err(ApiError::validation("title cannot be empty")
.with_field("title"));
}
// ...
}ApiError implements axum::response::IntoResponse, so any handler
returning Result<T, ApiError> produces a properly-shaped error response.
Structs§
- ApiError
- Standardized API error.