@@ -2,7 +2,6 @@ use crate::queries::errors::QueryError;
22use anyhow:: Error as AnyhowError ;
33use caryatid_module_rest_server:: messages:: RESTResponse ;
44use std:: fmt;
5- use std:: num:: ParseIntError ;
65
76/// Standard error types for the application
87#[ derive( Debug ) ]
@@ -49,12 +48,12 @@ impl RESTError {
4948 RESTError :: BadRequest ( "Invalid hex string" . to_string ( ) )
5049 }
5150
52- /// Resource not found error (flexible message)
51+ /// Resource not found error
5352 pub fn not_found ( message : & str ) -> Self {
5453 RESTError :: NotFound ( message. to_string ( ) )
5554 }
5655
57- /// Feature not implemented error (flexible message)
56+ /// Feature not implemented error
5857 pub fn not_implemented ( message : & str ) -> Self {
5958 RESTError :: NotImplemented ( message. to_string ( ) )
6059 }
@@ -64,21 +63,16 @@ impl RESTError {
6463 RESTError :: NotImplemented ( format ! ( "{} storage is disabled in config" , storage_type) )
6564 }
6665
67- /// Unexpected response error (flexible message)
66+ /// Unexpected response error
6867 pub fn unexpected_response ( message : & str ) -> Self {
6968 RESTError :: InternalServerError ( message. to_string ( ) )
7069 }
7170
72- /// Query failed error (flexible message)
71+ /// Query failed error
7372 pub fn query_failed ( message : & str ) -> Self {
7473 RESTError :: InternalServerError ( message. to_string ( ) )
7574 }
7675
77- /// Serialization failed error
78- pub fn serialization_failed ( what : & str , error : impl fmt:: Display ) -> Self {
79- RESTError :: InternalServerError ( format ! ( "Failed to serialize {}: {}" , what, error) )
80- }
81-
8276 /// Encoding failed error
8377 pub fn encoding_failed ( what : & str ) -> Self {
8478 RESTError :: InternalServerError ( format ! ( "Failed to encode {}" , what) )
@@ -107,12 +101,12 @@ impl From<AnyhowError> for RESTError {
107101 }
108102}
109103
110- /// Convert ParseIntError to RESTError (400 Bad Request)
111- impl From < ParseIntError > for RESTError {
112- fn from ( error : ParseIntError ) -> Self {
113- RESTError :: BadRequest ( error. to_string ( ) )
114- }
115- }
104+ // // / Convert ParseIntError to RESTError (400 Bad Request)
105+ // impl From<ParseIntError> for RESTError {
106+ // fn from(error: ParseIntError) -> Self {
107+ // RESTError::BadRequest(error.to_string())
108+ // }
109+ // }
116110
117111/// Convert hex decode errors to RESTError (400 Bad Request)
118112impl From < hex:: FromHexError > for RESTError {
@@ -147,8 +141,7 @@ impl From<QueryError> for RESTError {
147141 fn from ( error : QueryError ) -> Self {
148142 match error {
149143 QueryError :: NotFound { resource } => RESTError :: NotFound ( resource) ,
150- QueryError :: PartialNotFound { message } => RESTError :: BadRequest ( message) ,
151- QueryError :: QueryFailed { message } => RESTError :: InternalServerError ( message) ,
144+ QueryError :: Internal { message } => RESTError :: InternalServerError ( message) ,
152145 QueryError :: StorageDisabled { storage_type } => {
153146 RESTError :: storage_disabled ( & storage_type)
154147 }
@@ -158,8 +151,6 @@ impl From<QueryError> for RESTError {
158151 }
159152}
160153
161- pub type AppResult < T > = Result < T , RESTError > ;
162-
163154#[ cfg( test) ]
164155mod tests {
165156 use super :: * ;
@@ -192,13 +183,6 @@ mod tests {
192183 assert_eq ! ( app_error. status_code( ) , 500 ) ;
193184 }
194185
195- #[ test]
196- fn test_from_parse_int_error ( ) {
197- let result: Result < u64 , _ > = "not_a_number" . parse ( ) ;
198- let app_error: RESTError = result. unwrap_err ( ) . into ( ) ;
199- assert_eq ! ( app_error. status_code( ) , 400 ) ;
200- }
201-
202186 #[ test]
203187 fn test_from_hex_error ( ) {
204188 let result = hex:: decode ( "not_hex_gg" ) ;
0 commit comments