File tree 4 files changed +10
-4
lines changed
4 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ impl std::fmt::Display for Error {
55
55
}
56
56
}
57
57
58
+ const DUPLICATE_KEY : u32 = 23505 ;
59
+
58
60
impl Reject for Error { }
59
61
impl Reject for APILayerError { }
60
62
@@ -65,7 +67,7 @@ pub async fn return_error(r: Rejection) -> Result<impl Reply, Rejection> {
65
67
66
68
match e {
67
69
sqlx:: Error :: Database ( err) => {
68
- if err. code ( ) . unwrap ( ) . parse :: < i32 > ( ) . unwrap ( ) == 23505 {
70
+ if err. code ( ) . unwrap ( ) . parse :: < u32 > ( ) . unwrap ( ) == DUPLICATE_KEY {
69
71
Ok ( warp:: reply:: with_status (
70
72
"Account already exsists" . to_string ( ) ,
71
73
StatusCode :: UNPROCESSABLE_ENTITY ,
Original file line number Diff line number Diff line change @@ -60,14 +60,16 @@ impl std::fmt::Display for Error {
60
60
impl Reject for Error { }
61
61
impl Reject for APILayerError { }
62
62
63
+ const DUPLICATE_KEY : u32 = 23505 ;
64
+
63
65
#[ instrument]
64
66
pub async fn return_error ( r : Rejection ) -> Result < impl Reply , Rejection > {
65
67
if let Some ( crate :: Error :: DatabaseQueryError ( e) ) = r. find ( ) {
66
68
event ! ( Level :: ERROR , "Database query error" ) ;
67
69
68
70
match e {
69
71
sqlx:: Error :: Database ( err) => {
70
- if err. code ( ) . unwrap ( ) . parse :: < i32 > ( ) . unwrap ( ) == 23505 {
72
+ if err. code ( ) . unwrap ( ) . parse :: < u32 > ( ) . unwrap ( ) == DUPLICATE_KEY {
71
73
Ok ( warp:: reply:: with_status (
72
74
"Account already exsists" . to_string ( ) ,
73
75
StatusCode :: UNPROCESSABLE_ENTITY ,
Original file line number Diff line number Diff line change @@ -60,14 +60,16 @@ impl std::fmt::Display for Error {
60
60
impl Reject for Error { }
61
61
impl Reject for APILayerError { }
62
62
63
+ const DUPLICATE_KEY : u32 = 23505 ;
64
+
63
65
#[ instrument]
64
66
pub async fn return_error ( r : Rejection ) -> Result < impl Reply , Rejection > {
65
67
if let Some ( crate :: Error :: DatabaseQueryError ( e) ) = r. find ( ) {
66
68
event ! ( Level :: ERROR , "Database query error" ) ;
67
69
68
70
match e {
69
71
sqlx:: Error :: Database ( err) => {
70
- if err. code ( ) . unwrap ( ) . parse :: < i32 > ( ) . unwrap ( ) == 23505 {
72
+ if err. code ( ) . unwrap ( ) . parse :: < u32 > ( ) . unwrap ( ) == DUPLICATE_KEY {
71
73
Ok ( warp:: reply:: with_status (
72
74
"Account already exsists" . to_string ( ) ,
73
75
StatusCode :: UNPROCESSABLE_ENTITY ,
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ mod pagination_tests {
72
72
}
73
73
74
74
#[ test]
75
- fn missing_offset_paramater ( ) {
75
+ fn missing_offset_parameter ( ) {
76
76
let mut params = HashMap :: new ( ) ;
77
77
params. insert ( String :: from ( "limit" ) , String :: from ( "1" ) ) ;
78
78
You can’t perform that action at this time.
0 commit comments