@@ -26,7 +26,7 @@ pub enum BackendError {
2626 #[ error( "source repository missing primary mirror" ) ]
2727 SourceRepositoryMissingPrimaryMirror ,
2828
29- #[ error( "object not found: {0:?}" ) ]
29+ #[ error( "object not found: {}" , . 0 . clone ( ) . unwrap_or_default ( ) ) ]
3030 ObjectNotFound ( Option < String > ) ,
3131
3232 #[ error( "api key not found" ) ]
@@ -83,27 +83,16 @@ pub enum BackendError {
8383 S3Error ( String ) ,
8484}
8585
86- impl From < AzureError > for BackendError {
87- fn from ( error : AzureError ) -> BackendError {
88- match error. kind ( ) {
89- AzureErrorKind :: HttpResponse { status, error_code }
90- if * status == AzureStatusCode :: NotFound =>
91- {
92- BackendError :: ObjectNotFound ( error_code. clone ( ) )
93- }
94- _ => BackendError :: AzureError ( error) ,
95- }
96- }
97- }
98-
9986impl error:: ResponseError for BackendError {
10087 fn error_response ( & self ) -> HttpResponse {
101- error ! ( "Error: {}" , self ) ;
10288 let status_code = self . status_code ( ) ;
10389 let body = match status_code {
10490 e if e. is_client_error ( ) => self . to_string ( ) ,
10591 _ => format ! ( "Internal Server Error: {}" , self . to_string( ) ) ,
10692 } ;
93+ if status_code. is_server_error ( ) {
94+ error ! ( "Error: {}" , self ) ;
95+ }
10796 HttpResponse :: build ( status_code) . body ( body)
10897 }
10998
@@ -135,6 +124,20 @@ impl error::ResponseError for BackendError {
135124 }
136125}
137126
127+ // Azure API Errors
128+ impl From < AzureError > for BackendError {
129+ fn from ( error : AzureError ) -> BackendError {
130+ match error. kind ( ) {
131+ AzureErrorKind :: HttpResponse { status, error_code }
132+ if * status == AzureStatusCode :: NotFound =>
133+ {
134+ BackendError :: ObjectNotFound ( error_code. clone ( ) )
135+ }
136+ _ => BackendError :: AzureError ( error) ,
137+ }
138+ }
139+ }
140+
138141// S3 API Errors
139142fn get_rusoto_error_message < T : std:: error:: Error > (
140143 operation : & str ,
@@ -146,12 +149,7 @@ fn get_rusoto_error_message<T: std::error::Error>(
146149 RusotoError :: Credentials ( e) => format ! ( "{} Credentials Error: {}" , operation, e) ,
147150 RusotoError :: Validation ( e) => format ! ( "{} Validation Error: {}" , operation, e) ,
148151 RusotoError :: ParseError ( e) => format ! ( "{} Parse Error: {}" , operation, e) ,
149- RusotoError :: Unknown ( e) => format ! (
150- "{} Unknown Error: status {}, body {}" ,
151- operation,
152- e. status,
153- e. body_as_str( )
154- ) ,
152+ RusotoError :: Unknown ( e) => format ! ( "{} Unknown Error: status {}" , operation, e. status) ,
155153 RusotoError :: Blocking => format ! ( "{} Blocking Error" , operation) ,
156154 }
157155}
@@ -243,7 +241,7 @@ mod tests {
243241 assert_eq ! ( response. status( ) , StatusCode :: NOT_FOUND ) ;
244242 assert_eq ! (
245243 to_bytes( response. into_body( ) ) . await . unwrap( ) ,
246- Bytes :: from( "object not found: Some( \" test-key\" ) " )
244+ Bytes :: from( "object not found: test-key" )
247245 ) ;
248246 }
249247
@@ -293,7 +291,7 @@ mod tests {
293291 assert_eq ! ( response. status( ) , StatusCode :: BAD_GATEWAY ) ;
294292 assert_eq ! (
295293 to_bytes( response. into_body( ) ) . await . unwrap( ) ,
296- Bytes :: from( "Internal Server Error: s3 error: PutObject Unknown Error: status 500 Internal Server Error, body " )
294+ Bytes :: from( "Internal Server Error: s3 error: PutObject Unknown Error: status 500 Internal Server Error" )
297295 ) ;
298296 }
299297 }
@@ -326,7 +324,7 @@ mod tests {
326324 assert_eq ! ( response. status( ) , StatusCode :: NOT_FOUND ) ;
327325 assert_eq ! (
328326 to_bytes( response. into_body( ) ) . await . unwrap( ) ,
329- Bytes :: from( "object not found: Some( \" ResourceNotFound\" ) " )
327+ Bytes :: from( "object not found: ResourceNotFound" )
330328 ) ;
331329 }
332330
0 commit comments