heartwood every commit a ring
419 B raw
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};

pub struct AppError(pub StatusCode, pub String);

impl<E: std::fmt::Display> From<E> for AppError {
    fn from(e: E) -> Self {
        AppError(StatusCode::INTERNAL_SERVER_ERROR, format!("internal error: {e}"))
    }
}

impl IntoResponse for AppError {
    fn into_response(self) -> Response {
        (self.0, self.1).into_response()
    }
}