diff options
author | Cara Salter <cara@devcara.com> | 2022-04-27 14:44:33 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-04-27 14:44:33 -0400 |
commit | bc3132f22f3470d8b1d8189e23393d3bb4577480 (patch) | |
tree | b8d6466e4191a4e7e5e4a755102e82ffbff56b36 /src/errors.rs | |
parent | 9696669ff126cd2bcbc31e90651b464432b7947f (diff) | |
download | solard-bc3132f22f3470d8b1d8189e23393d3bb4577480.tar.gz solard-bc3132f22f3470d8b1d8189e23393d3bb4577480.zip |
List waifus
Also use environment variables and new error types
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() + } +} |