Skip to main content

standard_error/extras/
response.rs

1use crate::StandardError;
2#[cfg(feature = "askama")]
3use axum::response::Html;
4use axum::response::{IntoResponse, Response};
5use axum::Json;
6use serde_json::json;
7
8impl IntoResponse for StandardError {
9    fn into_response(self) -> Response {
10        #[cfg(feature = "askama")]
11        if let Some(html) = self.html {
12            return (self.status_code, Html(html)).into_response();
13        }
14        (self.status_code, Json(json!({"detail": self.message}))).into_response()
15    }
16}