aboutsummaryrefslogtreecommitdiff
path: root/src/errors.rs
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-04-27 14:44:33 -0400
committerCara Salter <cara@devcara.com>2022-04-27 14:44:33 -0400
commitbc3132f22f3470d8b1d8189e23393d3bb4577480 (patch)
treeb8d6466e4191a4e7e5e4a755102e82ffbff56b36 /src/errors.rs
parent9696669ff126cd2bcbc31e90651b464432b7947f (diff)
downloadsolard-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.rs30
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()
+ }
+}