standard-error 0.1.9

simplifies returning meaningful errors for axum services
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use crate::StandardError;
use axum::response::{Response, IntoResponse, Html};
use axum::Json;
use serde_json::json;

impl IntoResponse for StandardError {
    fn into_response(self) -> Response {
        #[cfg(feature = "askama")]
        if let Some(html) = self.html {
            return (self.status_code, Html(html)).into_response();
        }
        (self.status_code, Json(json!({"detail": self.message}))).into_response()
    }
}