From 1666d757b87578eed22b4e1c67420c602554295a Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 10 Sep 2022 17:50:21 +0200 Subject: Add `Unauthorized` error --- src/errors.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/errors.rs') diff --git a/src/errors.rs b/src/errors.rs index 2251ad4..e6f8e2c 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -17,6 +17,8 @@ pub enum AppError { TokenCreation, /// Raised when a passed token is not valid InvalidToken, + /// Raised if an user wants to do something can't do + Unauthorized, } /// Use `AppError` as response for an endpoint @@ -39,6 +41,10 @@ impl IntoResponse for AppError { "Token creation error".to_string(), ), AppError::InvalidToken => (StatusCode::BAD_REQUEST, "Invalid token".to_string()), + AppError::Unauthorized => ( + StatusCode::UNAUTHORIZED, + "Can't perform this action".to_string(), + ), }; let body = Json(json!({ -- cgit v1.2.3-71-g8e6c