@@ -938,9 +938,11 @@ public function send(string $method, string $url, array $options = [])
938
938
}
939
939
});
940
940
} catch (ConnectException $ e ) {
941
- $ this -> dispatchConnectionFailedEvent ( new Request ($ e ->getRequest ()) );
941
+ $ exception = new ConnectionException ($ e ->getMessage (), 0 , $ e );
942
942
943
- throw new ConnectionException ($ e ->getMessage (), 0 , $ e );
943
+ $ this ->dispatchConnectionFailedEvent (new Request ($ e ->getRequest ()), $ exception );
944
+
945
+ throw $ exception ;
944
946
}
945
947
}, $ this ->retryDelay ?? 100 , function ($ exception ) use (&$ shouldRetry ) {
946
948
$ result = $ shouldRetry ?? ($ this ->retryWhenCallback ? call_user_func ($ this ->retryWhenCallback , $ exception , $ this ) : true );
@@ -1028,9 +1030,11 @@ protected function makePromise(string $method, string $url, array $options = [],
1028
1030
})
1029
1031
->otherwise (function (OutOfBoundsException |TransferException $ e ) {
1030
1032
if ($ e instanceof ConnectException) {
1031
- $ this ->dispatchConnectionFailedEvent (new Request ($ e ->getRequest ()));
1033
+ $ exception = new ConnectionException ($ e ->getMessage (), 0 , $ e );
1034
+
1035
+ $ this ->dispatchConnectionFailedEvent (new Request ($ e ->getRequest ()), $ exception );
1032
1036
1033
- return new ConnectionException ( $ e -> getMessage (), 0 , $ e ) ;
1037
+ return $ exception ;
1034
1038
}
1035
1039
1036
1040
return $ e instanceof RequestException && $ e ->hasResponse () ? $ this ->populateResponse ($ this ->newResponse ($ e ->getResponse ())) : $ e ;
@@ -1496,12 +1500,13 @@ protected function dispatchResponseReceivedEvent(Response $response)
1496
1500
* Dispatch the ConnectionFailed event if a dispatcher is available.
1497
1501
*
1498
1502
* @param \Illuminate\Http\Client\Request $request
1503
+ * @param \Illuminate\Http\Client\ConnectionException $exception
1499
1504
* @return void
1500
1505
*/
1501
- protected function dispatchConnectionFailedEvent (Request $ request )
1506
+ protected function dispatchConnectionFailedEvent (Request $ request, ConnectionException $ exception )
1502
1507
{
1503
1508
if ($ dispatcher = $ this ->factory ?->getDispatcher()) {
1504
- $ dispatcher ->dispatch (new ConnectionFailed ($ request ));
1509
+ $ dispatcher ->dispatch (new ConnectionFailed ($ request, $ exception ));
1505
1510
}
1506
1511
}
1507
1512
0 commit comments