diff options
Diffstat (limited to 'src/errors.rs')
-rw-r--r-- | src/errors.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..a538e4a --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,30 @@ +use thiserror::Error; + +use axum::response::{Response, IntoResponse}; +use axum::http::StatusCode; +use axum::body; +use axum::Json; + +#[derive(Debug, Error)] +pub enum ServiceError { + #[error("Waifulib error: {0}")] + Waifulib(#[from] waifulib::errors::Error), + + #[error("Axum error: {0}")] + Axum(#[from] axum::Error), +} + +pub type StringResult<T = &'static str> = std::result::Result<T, ServiceError>; + +pub type JsonResult<T> = std::result::Result<T, ServiceError>; + +impl IntoResponse for ServiceError { + fn into_response(self) -> Response { + + let body = body::boxed(body::Full::from(self.to_string())); + Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(body) + .unwrap() + } +} |