contact-form/src/errors.rs

24 lines
497 B
Rust
Raw Normal View History

2023-02-23 16:12:59 +00:00
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
2022-12-03 16:08:23 +00:00
use tracing::error;
2022-11-01 19:45:06 +00:00
2023-02-23 16:12:59 +00:00
/// App error for conversion to anyhow error.
2022-11-01 19:45:06 +00:00
pub struct AppError(anyhow::Error);
impl IntoResponse for AppError {
fn into_response(self) -> Response {
2023-02-23 16:12:59 +00:00
// Log error.
2022-12-03 16:08:23 +00:00
error!("{:?}", self.0);
2023-02-25 20:33:45 +00:00
(StatusCode::BAD_REQUEST, self.0.to_string()).into_response()
2022-11-01 19:45:06 +00:00
}
}
impl From<anyhow::Error> for AppError {
fn from(err: anyhow::Error) -> Self {
Self(err)
2022-11-01 19:45:06 +00:00
}
}