diff options
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs index 232d588..d16106a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -9,6 +9,7 @@ use serde_json::json; pub enum AppError { BadRequest(&'static str), Conflict, + Csv(csv::Error), Database(sqlx::Error), MethodNotAllowed, NotFound, @@ -25,6 +26,12 @@ impl From<sqlx::Error> for AppError { } } +impl From<csv::Error> for AppError { + fn from(e: csv::Error) -> Self { + AppError::Csv(e) + } +} + impl From<JsonRejection> for AppError { fn from(rejection: JsonRejection) -> Self { AppError::Rejection(rejection.status(), rejection.body_text()) @@ -48,6 +55,13 @@ impl IntoResponse for AppError { let (status, message) = match self { AppError::BadRequest(message) => (StatusCode::BAD_REQUEST, message.to_owned()), AppError::Conflict => (StatusCode::CONFLICT, "already exists".to_owned()), + AppError::Csv(e) => { + tracing::error!("csv error: {e}"); + ( + StatusCode::INTERNAL_SERVER_ERROR, + "internal server error".to_owned(), + ) + } AppError::Database(e) => { tracing::error!("database error: {e}"); ( |
