contact-form/src/errors.rs

23 lines
497 B
Rust

use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
use tracing::error;
/// App error for conversion to anyhow error.
pub struct AppError(anyhow::Error);
impl IntoResponse for AppError {
fn into_response(self) -> Response {
// Log error.
error!("{:?}", self.0);
(StatusCode::BAD_REQUEST, self.0.to_string()).into_response()
}
}
impl From<anyhow::Error> for AppError {
fn from(err: anyhow::Error) -> Self {
Self(err)
}
}