diff options
author | Santo Cariotti <santo@dcariotti.me> | 2022-08-23 18:57:16 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2022-08-23 18:57:16 +0200 |
commit | 2231ab6730552d3b58b00ae42d490743a29d7c8b (patch) | |
tree | 4a9612ec08398b8abc2e4ce7c30825f7ef18659c /server/src/errors.rs | |
parent | bba5f252f265e6102d2f052e9ca100efe318508f (diff) |
Add docs
Diffstat (limited to 'server/src/errors.rs')
-rw-r--r-- | server/src/errors.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/server/src/errors.rs b/server/src/errors.rs index 304d744..e541eda 100644 --- a/server/src/errors.rs +++ b/server/src/errors.rs @@ -5,16 +5,29 @@ use axum::{ }; use serde_json::json; +/// All errors raised by the web app pub enum AppError { + /// Generic error, never called yet Generic, + /// Database error Database, + /// Generic bad request. It is handled with a message value BadRequest(String), + /// Not found error NotFound, + /// Raised when a token is not good created TokenCreation, + /// Raised when a passed token is not valid InvalidToken, } +/// Use `AppError` as response for an endpoint impl IntoResponse for AppError { + /// Matches `AppError` into a tuple of status and error message. + /// The response will be a JSON in the format of: + /// ```json + /// { "error": "<message>" } + /// ``` fn into_response(self) -> Response { let (status, error_message) = match self { AppError::Generic => ( @@ -42,6 +55,7 @@ impl IntoResponse for AppError { } } +/// Transforms a `sqlx::Error` into a `AppError::Databse` error impl From<sqlx::Error> for AppError { fn from(_error: sqlx::Error) -> AppError { AppError::Database |