aboutsummaryrefslogtreecommitdiff
path: root/src/error/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error/mod.rs')
-rw-r--r--src/error/mod.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/error/mod.rs b/src/error/mod.rs
new file mode 100644
index 0000000..55d7250
--- /dev/null
+++ b/src/error/mod.rs
@@ -0,0 +1,50 @@
1mod client;
2mod server;
3
4pub use client::ClientError;
5pub use server::ServerError;
6
7use argon2::password_hash::Error as PasswordHashError;
8use axum::extract::rejection::JsonRejection;
9use axum_extra::typed_header::TypedHeaderRejection;
10use sea_orm::DbErr;
11
12pub enum ApiError {
13 Client(ClientError),
14 Server(ServerError),
15}
16
17impl From<ClientError> for ApiError {
18 fn from(value: ClientError) -> Self {
19 Self::Client(value)
20 }
21}
22impl From<ServerError> for ApiError {
23 fn from(value: ServerError) -> Self {
24 Self::Server(value)
25 }
26}
27
28impl From<JsonRejection> for ApiError {
29 fn from(value: JsonRejection) -> Self {
30 Self::Client(ClientError::BadJsonBody(value.body_text()))
31 }
32}
33
34impl From<TypedHeaderRejection> for ApiError {
35 fn from(value: TypedHeaderRejection) -> Self {
36 Self::Client(ClientError::BadAuthTokenHeader(value.to_string()))
37 }
38}
39
40impl From<DbErr> for ApiError {
41 fn from(value: DbErr) -> Self {
42 Self::Server(ServerError::Database(value.to_string()))
43 }
44}
45
46impl From<PasswordHashError> for ApiError {
47 fn from(value: PasswordHashError) -> Self {
48 Self::Server(ServerError::PasswordHash(value.to_string()))
49 }
50}