summaryrefslogtreecommitdiffstats
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/error.rs b/src/error.rs
index ef8ddd3..2704519 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,6 +1,9 @@
use std::fmt::Display;
-use poem::{error::ResponseError, http::StatusCode};
+use poem::{
+ error::{ParseMultipartError, ResponseError},
+ http::StatusCode,
+};
use sqlx::postgres::PgDatabaseError;
#[derive(Debug)]
@@ -11,6 +14,11 @@ pub enum Error {
DatabaseError(sqlx::Error),
NotFound,
MissingField,
+ Unauthorized,
+ MultipartError,
+ BadRequest,
+ UnsupportedFileType(String),
+ UploadDirectory(String),
}
impl Display for Error {
@@ -22,6 +30,15 @@ impl Display for Error {
Error::DatabaseError(error) => write!(f, "database error: {}", error),
Error::NotFound => write!(f, "not found"),
Error::MissingField => write!(f, "missing field in row"),
+ Error::Unauthorized => write!(f, "user unauthorized"),
+ Error::MultipartError => write!(f, "error parsing multipart form data"),
+ Error::BadRequest => write!(f, "bad request"),
+ Error::UnsupportedFileType(filetype) => {
+ write!(f, "unsupported file upload type: {}", filetype)
+ }
+ Error::UploadDirectory(directory) => {
+ write!(f, "invalid uploads directory: {}", directory)
+ }
}
}
}
@@ -37,6 +54,11 @@ impl ResponseError for Error {
Error::NotFound => StatusCode::NOT_FOUND,
Error::SQLError(_) => StatusCode::INTERNAL_SERVER_ERROR,
Error::MissingField => StatusCode::INTERNAL_SERVER_ERROR,
+ Error::Unauthorized => StatusCode::UNAUTHORIZED,
+ Error::MultipartError => StatusCode::BAD_REQUEST,
+ Error::BadRequest => StatusCode::BAD_REQUEST,
+ Error::UnsupportedFileType(_) => StatusCode::BAD_REQUEST,
+ Error::UploadDirectory(_) => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
@@ -67,3 +89,9 @@ impl From<sqlx::Error> for Error {
}
}
}
+
+impl From<ParseMultipartError> for Error {
+ fn from(e: ParseMultipartError) -> Self {
+ Error::MultipartError
+ }
+}