diff options
| author | Daniel Hader <[email protected]> | 2026-05-11 19:28:00 -0500 |
|---|---|---|
| committer | Daniel Hader <[email protected]> | 2026-05-11 19:28:00 -0500 |
| commit | 36fad793c3be58b220ae319a45c8cd8afbae09fa (patch) | |
| tree | 0f072c9f3dd45b4295ded00d8a7f2c318238b688 /src/routes/errors.rs | |
| parent | a005add5513182abb0b1230cf514c7a45b290e4b (diff) | |
user route and database pooling using r2d2
Diffstat (limited to 'src/routes/errors.rs')
| -rw-r--r-- | src/routes/errors.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/routes/errors.rs b/src/routes/errors.rs new file mode 100644 index 0000000..6261d75 --- /dev/null +++ b/src/routes/errors.rs @@ -0,0 +1,26 @@ +use axum::{Json, body::Body, http::{Response, StatusCode}, response::IntoResponse}; +use serde_json::{json}; + +pub enum RouteError { + Internal(String), + UserCreateEmailExists(String), + UserCreateUsernameExists(String), +} + +impl IntoResponse for RouteError { + fn into_response(self) -> Response<Body> { + let (status, message) = match self { + Self::Internal(message) => { + (StatusCode::INTERNAL_SERVER_ERROR, message) + }, + RouteError::UserCreateEmailExists(email) => { + (StatusCode::BAD_REQUEST, format!("user with email \"{}\" already exists", email)) + }, + RouteError::UserCreateUsernameExists(username) => { + (StatusCode::BAD_REQUEST, format!("user with username \"{}\" already exists", username)) + } + }; + + (status, Json(json!({"error": message}))).into_response() + } +} |
