|
@@ -32,6 +32,12 @@ pub enum AppError {
|
|
|
|
|
|
|
|
#[error("Unauthorized")]
|
|
#[error("Unauthorized")]
|
|
|
Auth,
|
|
Auth,
|
|
|
|
|
+
|
|
|
|
|
+ #[error("Invalid UUID")]
|
|
|
|
|
+ InvalidUuid(#[from] uuid::Error),
|
|
|
|
|
+
|
|
|
|
|
+ #[error("{0}")]
|
|
|
|
|
+ Forbidden(String)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
impl ResponseError for AppError {
|
|
impl ResponseError for AppError {
|
|
@@ -42,7 +48,9 @@ impl ResponseError for AppError {
|
|
|
AppError::Database(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
AppError::Database(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
|
AppError::JsonDeserializationError(_) => StatusCode::BAD_REQUEST,
|
|
AppError::JsonDeserializationError(_) => StatusCode::BAD_REQUEST,
|
|
|
AppError::NotFound(_) => StatusCode::NOT_FOUND,
|
|
AppError::NotFound(_) => StatusCode::NOT_FOUND,
|
|
|
- AppError::Auth => StatusCode::UNAUTHORIZED
|
|
|
|
|
|
|
+ AppError::Auth => StatusCode::UNAUTHORIZED,
|
|
|
|
|
+ AppError::InvalidUuid(_) => StatusCode::BAD_REQUEST,
|
|
|
|
|
+ AppError::Forbidden(_) => StatusCode::FORBIDDEN
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -72,4 +80,8 @@ impl AppError {
|
|
|
pub fn not_found(msg: &str) -> Self {
|
|
pub fn not_found(msg: &str) -> Self {
|
|
|
AppError::NotFound(msg.into())
|
|
AppError::NotFound(msg.into())
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ pub fn forbidden(msg: &str) -> Self {
|
|
|
|
|
+ AppError::Forbidden(msg.into())
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|