|
|
@@ -25,7 +25,13 @@ pub enum AppError {
|
|
|
Database(#[from] sqlx::Error),
|
|
|
|
|
|
#[error("{0}")]
|
|
|
- JsonDeserializationError(String)
|
|
|
+ JsonDeserializationError(String),
|
|
|
+
|
|
|
+ #[error("{0}")]
|
|
|
+ NotFound(String),
|
|
|
+
|
|
|
+ #[error("Unauthorized")]
|
|
|
+ Auth,
|
|
|
}
|
|
|
|
|
|
impl ResponseError for AppError {
|
|
|
@@ -34,7 +40,9 @@ impl ResponseError for AppError {
|
|
|
AppError::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
|
AppError::InvalidInput(_) => StatusCode::BAD_REQUEST,
|
|
|
AppError::Database(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
|
- AppError::JsonDeserializationError(_) => StatusCode::BAD_REQUEST
|
|
|
+ AppError::JsonDeserializationError(_) => StatusCode::BAD_REQUEST,
|
|
|
+ AppError::NotFound(_) => StatusCode::NOT_FOUND,
|
|
|
+ AppError::Auth => StatusCode::UNAUTHORIZED
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -60,4 +68,8 @@ impl AppError {
|
|
|
pub fn invalid_input(msg: &str) -> Self {
|
|
|
AppError::InvalidInput(msg.into())
|
|
|
}
|
|
|
+
|
|
|
+ pub fn not_found(msg: &str) -> Self {
|
|
|
+ AppError::NotFound(msg.into())
|
|
|
+ }
|
|
|
}
|