File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -461,6 +461,15 @@ impl HttpError {
461
461
. into_response ( )
462
462
}
463
463
464
+ pub async fn error_message_from_bytes (
465
+ bytes : hyper:: body:: Bytes ,
466
+ ) -> ( Cow < ' static , str > , Cow < ' static , str > ) {
467
+ let ResponseErrorMessage { code, message } =
468
+ serde_json:: from_slice ( & bytes) . expect ( "Couldn't deserialize as json" ) ;
469
+
470
+ ( code, message)
471
+ }
472
+
464
473
// Tests might parse a response back into a message
465
474
#[ cfg( any( test, feature = "testing" ) ) ]
466
475
pub async fn from_response < B > ( response : Response < B > ) -> Self
@@ -469,12 +478,12 @@ impl HttpError {
469
478
B :: Error : fmt:: Debug ,
470
479
{
471
480
let ( parts, body) = response. into_parts ( ) ;
472
- let ResponseErrorMessage { code, message } = serde_json :: from_slice (
473
- & hyper:: body:: to_bytes ( body)
481
+ let ( code, message) = Self :: error_message_from_bytes (
482
+ hyper:: body:: to_bytes ( body)
474
483
. await
475
484
. expect ( "Couldn't convert to bytes" ) ,
476
485
)
477
- . expect ( "Couldn't deserialize as json" ) ;
486
+ . await ;
478
487
479
488
Self {
480
489
status_code : parts. status ,
You can’t perform that action at this time.
0 commit comments