summaryrefslogtreecommitdiffstats
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs26
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()
+ }
+}