use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
use serror::serialize_error;
pub type AppResult<T> = Result<T, AppError>;
pub struct AppError(anyhow::Error);
impl IntoResponse for AppError {
fn into_response(self) -> Response {
(StatusCode::INTERNAL_SERVER_ERROR, serialize_error(self.0)).into_response()
}
}
impl<E> From<E> for AppError
where
E: Into<anyhow::Error>,
{
fn from(err: E) -> Self {
Self(err.into())
}
}
pub type AuthResult<T> = Result<T, AuthError>;
pub struct AuthError(anyhow::Error);
impl IntoResponse for AuthError {
fn into_response(self) -> Response {
(StatusCode::UNAUTHORIZED, serialize_error(self.0)).into_response()
}
}
impl<E> From<E> for AuthError
where
E: Into<anyhow::Error>,
{
fn from(err: E) -> Self {
Self(err.into())
}
}