aboutsummaryrefslogtreecommitdiff
path: root/src/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/errors.rs')
-rw-r--r--src/errors.rs49
1 files changed, 0 insertions, 49 deletions
diff --git a/src/errors.rs b/src/errors.rs
deleted file mode 100644
index dcc0ae8..0000000
--- a/src/errors.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-use axum::body;
-use axum::response::{IntoResponse, Response, Html};
-use hyper::StatusCode;
-use thiserror::Error;
-
-#[derive(Error, Debug)]
-pub enum ServiceError {
- #[error("No config file")]
- MissingConfig,
- #[error("Invalid config file: {0}")]
- InvalidConfig(#[from] toml::de::Error),
- #[error("Not Authorized")]
- NotAuthorized,
- #[error("Not Found")]
- NotFound,
- #[error("Axum: {0}")]
- Axum(#[from] axum::Error),
- #[error("SQL: {0}")]
- Sql(#[from] sqlx::Error),
- #[error("Bcrypt: {0}")]
- Bcrypt(#[from] bcrypt::BcryptError),
- #[error("Parse Error: {0}")]
- Parse(String),
- #[error("Email: {0}")]
- Email(String),
-}
-
-pub type StringResult<T = String> = Result<T, ServiceError>;
-pub type HtmlResult<T = Html<String>> = Result<T, ServiceError>;
-pub type JsonResult<T> = Result<T, ServiceError>;
-
-impl IntoResponse for ServiceError {
- fn into_response(self) -> axum::response::Response {
- let body = body::boxed(body::Full::from(self.to_string()));
-
- let status = match self {
- ServiceError::NotFound => StatusCode::NOT_FOUND,
- ServiceError::NotAuthorized => StatusCode::UNAUTHORIZED,
- _ => StatusCode::INTERNAL_SERVER_ERROR,
- };
- Response::builder().status(status).body(body).unwrap()
- }
-}
-
-impl From<ipnetwork::IpNetworkError> for ServiceError {
- fn from(e: ipnetwork::IpNetworkError) -> Self {
- Self::Parse(e.to_string())
- }
-}