From 372b484e8a6366346d52ff44bbdaa6aad1cc2daa Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Fri, 27 May 2022 23:13:52 -0400 Subject: initial axum scaffold --- src/errors.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 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..70b1a43 --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,27 @@ +use axum::{response::{Response, IntoResponse}, body::{boxed, self}}; +use hyper::StatusCode; +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum ServiceError { + #[error("Solarlib error: {0}")] + Solarlib(#[from] solarlib::errors::Error), + + #[error("Axum error: {0}")] + Axum(#[from] axum::Error), +} + +pub type StringResult = Result; + +pub type JsonResult = 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