blob: a538e4a3a2f8885ce5d3552caa80e5cb7dc54530 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()
}
}
|