diff options
author | Cara Salter <cara@devcara.com> | 2022-05-27 23:13:52 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-05-27 23:13:52 -0400 |
commit | 372b484e8a6366346d52ff44bbdaa6aad1cc2daa (patch) | |
tree | 29b9f5c2dcd07c54057fc86a8f0cc5861b8c0a6d /src/errors.rs | |
parent | ca5c737f047119f31e42a8700b8ae1ad4fabd17a (diff) | |
download | homeworld-372b484e8a6366346d52ff44bbdaa6aad1cc2daa.tar.gz homeworld-372b484e8a6366346d52ff44bbdaa6aad1cc2daa.zip |
initial axum scaffold
Diffstat (limited to 'src/errors.rs')
-rw-r--r-- | src/errors.rs | 27 |
1 files changed, 27 insertions, 0 deletions
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<T = &'static str> = Result<T, ServiceError>; + +pub type JsonResult<T> = 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() + } +} |