blob: d76db92719e683368d071dfa658d039a1049fa8e (
plain) (
tree)
|
|
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("Solarlib error: {0}")]
Solarlib(#[from] solarlib::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>;
pub type NoneResult = std::result::Result<(), 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()
}
}
|