Files
mnemosyne/src/error.rs

39 lines
911 B
Rust

use axum::response::{IntoResponse, Response};
use crate::database::DatabaseError;
pub struct CompositeError(Response);
impl IntoResponse for CompositeError {
fn into_response(self) -> Response {
self.0
}
}
macro_rules! composite_from {
($($t:ty),+ $(,)?) => {
$(
impl From<$t> for CompositeError {
fn from(e: $t) -> Self {
CompositeError(e.into_response())
}
}
)+
};
}
composite_from!(
crate::users::auth::AuthError,
crate::users::UserError,
crate::users::sessions::SessionError,
crate::tags::TagError,
crate::persons::PersonError,
crate::quotes::QuoteError,
DatabaseError,
// RedirectViaError,
);
impl From<sqlx::Error> for CompositeError {
fn from(value: sqlx::Error) -> Self {
CompositeError(DatabaseError::from(value).into_response())
}
}