From bc3132f22f3470d8b1d8189e23393d3bb4577480 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Wed, 27 Apr 2022 14:44:33 -0400 Subject: List waifus Also use environment variables and new error types --- src/errors.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/errors.rs (limited to 'src/errors.rs') 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 = std::result::Result; + +pub type JsonResult = std::result::Result; + +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() + } +} -- cgit v1.2.3