From 04e19765aca471fd85199714699aaf827d04608d Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Sun, 27 Oct 2024 13:58:51 +0100 Subject: Refactor: Organize modules initially --- src/error.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/error.rs (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..72378ae --- /dev/null +++ b/src/error.rs @@ -0,0 +1,23 @@ +use axum::http::StatusCode; +use axum::response::IntoResponse; + +pub struct AppError(anyhow::Error); + +impl IntoResponse for AppError { + fn into_response(self) -> axum::response::Response { + ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Something went wrong: {}", self.0), + ) + .into_response() + } +} + +impl From for AppError +where + E: Into, +{ + fn from(err: E) -> Self { + Self(err.into()) + } +} -- cgit v1.2.3