summaryrefslogtreecommitdiff
path: root/server/src/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/errors.rs')
-rw-r--r--server/src/errors.rs14
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