mod client; mod server; pub use client::ClientError; pub use server::ServerError; use argon2::password_hash::Error as PasswordHashError; use axum::extract::rejection::{JsonRejection, QueryRejection}; use axum_extra::typed_header::TypedHeaderRejection; use sea_orm::DbErr; pub enum ApiError { Client(ClientError), Server(ServerError), } impl From for ApiError { #[inline] fn from(value: ClientError) -> Self { Self::Client(value) } } impl From for ApiError { #[inline] fn from(value: ServerError) -> Self { Self::Server(value) } } impl From for ApiError { fn from(value: JsonRejection) -> Self { ClientError::BadJsonBody(value.body_text()).into() } } impl From for ApiError { fn from(value: QueryRejection) -> Self { ClientError::BadJsonBody(value.body_text()).into() } } impl From for ApiError { fn from(value: TypedHeaderRejection) -> Self { ClientError::BadAuthTokenHeader(value.to_string()).into() } } impl From for ApiError { fn from(value: DbErr) -> Self { ServerError::Database(value.to_string()).into() } } impl From for ApiError { fn from(value: PasswordHashError) -> Self { ServerError::PasswordHash(value.to_string()).into() } }