diff options
author | Toby Vincent <tobyv@tobyvin.dev> | 2024-03-20 14:22:24 -0500 |
---|---|---|
committer | Toby Vincent <tobyv@tobyvin.dev> | 2024-03-20 19:21:29 -0500 |
commit | f977dce01be9de61a64b94aab883fb43949234b3 (patch) | |
tree | e8b3b5b59b10d43619198ff7d0f9f0e10bed0818 /src/error.rs |
chore: initial commit
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..1f4b354 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,26 @@ +use axum::{ + http::StatusCode, + response::{IntoResponse, Response}, + Json, +}; + +pub type Result<T, E = Error> = std::result::Result<T, E>; + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("IO error: {0}")] + IO(#[from] std::io::Error), + + #[error("Axum Error: {0:?}")] + Axum(#[from] axum::Error), +} + +impl IntoResponse for Error { + fn into_response(self) -> Response { + let body = Json(serde_json::json!({ + "error": self.to_string(), + })); + + (StatusCode::INTERNAL_SERVER_ERROR, body).into_response() + } +} |