From 2231ab6730552d3b58b00ae42d490743a29d7c8b Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 23 Aug 2022 18:57:16 +0200 Subject: Add docs --- server/src/errors.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'server/src/errors.rs') 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": "" } + /// ``` 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 for AppError { fn from(_error: sqlx::Error) -> AppError { AppError::Database -- cgit v1.2.3-18-g5258