@@ -466,11 +466,23 @@ public static function request($url, $headers = [], $data = [], $type = self::GE
466466 $ transport = self ::get_transport ($ capabilities );
467467 }
468468
469- $ response = $ transport ->request ($ url , $ headers , $ data , $ options );
469+ try {
470+ $ response = $ transport ->request ($ url , $ headers , $ data , $ options );
471+
472+ $ options ['hooks ' ]->dispatch ('requests.before_parse ' , [&$ response , $ url , $ headers , $ data , $ type , $ options ]);
470473
471- $ options ['hooks ' ]->dispatch ('requests.before_parse ' , [&$ response , $ url , $ headers , $ data , $ type , $ options ]);
474+ $ parsed_response = self ::parse_response ($ response , $ url , $ headers , $ data , $ options );
475+ }
476+ catch (Exception $ e ) {
477+ $ options ['hooks ' ]->dispatch ('requests.failed ' , [$ e , $ url , $ headers , $ data , $ type , $ options ]);
478+ throw $ e ;
479+ }
480+ catch (InvalidArgument $ e ) {
481+ $ options ['hooks ' ]->dispatch ('requests.failed ' , [$ e , $ url , $ headers , $ data , $ type , $ options ]);
482+ throw $ e ;
483+ }
472484
473- return self :: parse_response ( $ response , $ url , $ headers , $ data , $ options ) ;
485+ return $ parsed_response ;
474486 }
475487
476488 /**
0 commit comments