blob: 07db26f7ef53a56282c64216040a2cb36ef27086 (
plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
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<ClientError> for ApiError {
#[inline]
fn from(value: ClientError) -> Self {
Self::Client(value)
}
}
impl From<ServerError> for ApiError {
#[inline]
fn from(value: ServerError) -> Self {
Self::Server(value)
}
}
impl From<JsonRejection> for ApiError {
fn from(value: JsonRejection) -> Self {
ClientError::BadJsonBody(value.body_text()).into()
}
}
impl From<QueryRejection> for ApiError {
fn from(value: QueryRejection) -> Self {
ClientError::BadJsonBody(value.body_text()).into()
}
}
impl From<TypedHeaderRejection> for ApiError {
fn from(value: TypedHeaderRejection) -> Self {
ClientError::BadAuthTokenHeader(value.to_string()).into()
}
}
impl From<DbErr> for ApiError {
fn from(value: DbErr) -> Self {
ServerError::Database(value.to_string()).into()
}
}
impl From<PasswordHashError> for ApiError {
fn from(value: PasswordHashError) -> Self {
ServerError::PasswordHash(value.to_string()).into()
}
}
|