From 66e677a8543285ed424d616092fb09c518b32fa4 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 21 Aug 2022 18:32:56 +0200 Subject: Init --- src/errors.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/errors.rs (limited to 'src/errors.rs') diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..6fd0a61 --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,24 @@ +use axum::{ + http::StatusCode, + response::{IntoResponse, Response}, + Json, +}; +use serde_json::json; + +pub enum Error { + Generic, +} + +impl IntoResponse for Error { + fn into_response(self) -> Response { + let (status, error_message) = match self { + Error::Generic => (StatusCode::INTERNAL_SERVER_ERROR, "User not found"), + }; + + let body = Json(json!({ + "error": error_message, + })); + + (status, body).into_response() + } +} -- cgit v1.2.3-18-g5258