repos

darkfurrow.com-rust

mirror archived upstream

A living almanac of seasons, soil, and the quiet knowledge that used to be common. Rust axum with minijinja and Vite.

agriculturealmanacaxumfolk-knowledgegardeningminijinjarustseasonalvite

606 B · 20 lines · Rust Raw History
 1use axum::http::StatusCode;
 2use axum::response::{IntoResponse, Response};
 3
 4pub struct AppError(pub StatusCode, pub String);
 5
 6impl<E: std::fmt::Display> From<E> for AppError {
 7    fn from(e: E) -> Self {
 8        // Log the detail, serve a generic body: template and IO error strings
 9        // can leak paths and internals to the client.
10        tracing::error!("internal error: {e}");
11        AppError(StatusCode::INTERNAL_SERVER_ERROR, "internal server error".to_string())
12    }
13}
14
15impl IntoResponse for AppError {
16    fn into_response(self) -> Response {
17        (self.0, self.1).into_response()
18    }
19}