@@ -27,11 +27,15 @@ pub enum ErrorKind {
27
27
EntityNotFound ,
28
28
ResourceNotFound ,
29
29
IpHeaderNotFound ,
30
+
30
31
RateLimitReached ,
31
32
InternalServer ,
32
33
MissingEnvVar ,
33
34
ConnectionPool ,
35
+
36
+ // Std errors
34
37
ParseInt ,
38
+ FromUtf8 ,
35
39
36
40
// External error kinds
37
41
R2D2 ,
@@ -49,24 +53,28 @@ macros::error_from!(Figment => figment::Error);
49
53
macros:: error_from!( Serde => serde_json:: Error ) ;
50
54
macros:: error_from!( Axum => axum:: Error ) ;
51
55
macros:: error_from!( Axum => axum:: http:: Error ) ;
56
+ macros:: error_from!( FromUtf8 => std:: string:: FromUtf8Error ) ;
52
57
53
58
impl std:: fmt:: Display for ErrorKind {
54
59
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
55
60
use ErrorKind :: * ;
56
61
57
62
match self {
58
63
InvalidParameter => write ! ( f, "invalid parameter" ) ,
59
- R2D2 => write ! ( f, "r2d2 error" ) ,
60
- Mysql => write ! ( f, "mysql error" ) ,
61
64
EntityNotFound => write ! ( f, "entity not found" ) ,
62
65
IpHeaderNotFound => write ! ( f, "ip header not found" ) ,
63
66
RateLimitReached => write ! ( f, "rate limit reached on given the sliding window" ) ,
64
67
InternalServer => write ! ( f, "an unexpected error occured" ) ,
65
68
ResourceNotFound => write ! ( f, "the queried resource was not found" ) ,
66
- Redis => write ! ( f, "redis error" ) ,
67
69
MissingEnvVar => write ! ( f, "an environment variable is missing" ) ,
68
70
ConnectionPool => write ! ( f, "an error occured while setting-up a connection pool" ) ,
71
+
69
72
ParseInt => write ! ( f, "can't parse int" ) ,
73
+ FromUtf8 => write ! ( f, "invalid utf8 string" ) ,
74
+
75
+ R2D2 => write ! ( f, "r2d2 error" ) ,
76
+ Mysql => write ! ( f, "mysql error" ) ,
77
+ Redis => write ! ( f, "redis error" ) ,
70
78
Figment => write ! ( f, "figment error" ) ,
71
79
Serde => write ! ( f, "serde error" ) ,
72
80
Axum => write ! ( f, "axum error" ) ,
@@ -83,20 +91,23 @@ impl Serialize for ErrorKind {
83
91
84
92
match self {
85
93
InvalidParameter => s. serialize_unit_variant ( "ErrorKind" , 0 , "InvalidParameter" ) ,
86
- R2D2 => s. serialize_unit_variant ( "ErrorKind" , 1 , "R2D2" ) ,
87
- Mysql => s. serialize_unit_variant ( "ErrorKind" , 2 , "Mysql" ) ,
88
- EntityNotFound => s. serialize_unit_variant ( "ErrorKind" , 3 , "EntityNotFound" ) ,
89
- IpHeaderNotFound => s. serialize_unit_variant ( "ErrorKind" , 4 , "IpHeaderNotFound" ) ,
90
- RateLimitReached => s. serialize_unit_variant ( "ErrorKind" , 5 , "RateLimitReached" ) ,
91
- InternalServer => s. serialize_unit_variant ( "ErrorKind" , 6 , "InternalServerError" ) ,
92
- ResourceNotFound => s. serialize_unit_variant ( "ErrorKind" , 7 , "ResourceNotFound" ) ,
93
- Redis => s. serialize_unit_variant ( "ErrorKind" , 8 , "Redis" ) ,
94
- MissingEnvVar => s. serialize_unit_variant ( "ErrorKind" , 9 , "MissingEnvVar" ) ,
95
- ConnectionPool => s. serialize_unit_variant ( "ErrorKind" , 10 , "ConnectionPool" ) ,
96
- ParseInt => s. serialize_unit_variant ( "ErrorKind" , 11 , "ParseInt" ) ,
97
- Figment => s. serialize_unit_variant ( "ErrorKind" , 11 , "Figment" ) ,
98
- Serde => s. serialize_unit_variant ( "ErrorKind" , 12 , "Serde" ) ,
99
- Axum => s. serialize_unit_variant ( "ErrorKind" , 13 , "Axum" ) ,
94
+ EntityNotFound => s. serialize_unit_variant ( "ErrorKind" , 1 , "EntityNotFound" ) ,
95
+ IpHeaderNotFound => s. serialize_unit_variant ( "ErrorKind" , 2 , "IpHeaderNotFound" ) ,
96
+ RateLimitReached => s. serialize_unit_variant ( "ErrorKind" , 3 , "RateLimitReached" ) ,
97
+ InternalServer => s. serialize_unit_variant ( "ErrorKind" , 4 , "InternalServerError" ) ,
98
+ ResourceNotFound => s. serialize_unit_variant ( "ErrorKind" , 5 , "ResourceNotFound" ) ,
99
+ MissingEnvVar => s. serialize_unit_variant ( "ErrorKind" , 6 , "MissingEnvVar" ) ,
100
+ ConnectionPool => s. serialize_unit_variant ( "ErrorKind" , 7 , "ConnectionPool" ) ,
101
+
102
+ ParseInt => s. serialize_unit_variant ( "ErrorKind" , 8 , "ParseInt" ) ,
103
+ FromUtf8 => s. serialize_unit_variant ( "ErrorKind" , 9 , "FromUtf8" ) ,
104
+
105
+ R2D2 => s. serialize_unit_variant ( "ErrorKind" , 10 , "R2D2" ) ,
106
+ Mysql => s. serialize_unit_variant ( "ErrorKind" , 11 , "Mysql" ) ,
107
+ Redis => s. serialize_unit_variant ( "ErrorKind" , 12 , "Redis" ) ,
108
+ Figment => s. serialize_unit_variant ( "ErrorKind" , 13 , "Figment" ) ,
109
+ Serde => s. serialize_unit_variant ( "ErrorKind" , 14 , "Serde" ) ,
110
+ Axum => s. serialize_unit_variant ( "ErrorKind" , 15 , "Axum" ) ,
100
111
}
101
112
}
102
113
}
@@ -109,17 +120,20 @@ impl From<ErrorKind> for StatusCode {
109
120
110
121
match kind {
111
122
InvalidParameter => Self :: BAD_REQUEST ,
112
- R2D2 => Self :: INTERNAL_SERVER_ERROR ,
113
- Mysql => Self :: INTERNAL_SERVER_ERROR ,
114
123
EntityNotFound => Self :: NOT_FOUND ,
115
124
IpHeaderNotFound => Self :: BAD_REQUEST ,
116
125
RateLimitReached => Self :: TOO_MANY_REQUESTS ,
117
126
InternalServer => Self :: INTERNAL_SERVER_ERROR ,
118
127
ResourceNotFound => Self :: NOT_FOUND ,
119
- Redis => Self :: INTERNAL_SERVER_ERROR ,
120
128
MissingEnvVar => Self :: INTERNAL_SERVER_ERROR ,
121
129
ConnectionPool => Self :: INTERNAL_SERVER_ERROR ,
130
+
122
131
ParseInt => Self :: INTERNAL_SERVER_ERROR ,
132
+ FromUtf8 => Self :: INTERNAL_SERVER_ERROR ,
133
+
134
+ R2D2 => Self :: INTERNAL_SERVER_ERROR ,
135
+ Mysql => Self :: INTERNAL_SERVER_ERROR ,
136
+ Redis => Self :: INTERNAL_SERVER_ERROR ,
123
137
Figment => Self :: INTERNAL_SERVER_ERROR ,
124
138
Serde => Self :: INTERNAL_SERVER_ERROR ,
125
139
Axum => Self :: INTERNAL_SERVER_ERROR ,
0 commit comments