@@ -935,15 +935,20 @@ public function send(string $method, string $url, array $options = [])
935
935
}
936
936
}
937
937
});
938
- } catch (ConnectException $ e ) {
939
- $ exception = new ConnectionException ($ e ->getMessage (), 0 , $ e );
940
- $ request = new Request ($ e ->getRequest ());
938
+ } catch (TransferException $ e ) {
939
+ if ($ e instanceof ConnectException) {
940
+ $ this ->marshalConnectionException ($ e );
941
+ }
941
942
942
- $ this ->factory ?->recordRequestResponsePair($ request , null );
943
+ if ($ e instanceof RequestException && ! $ e ->hasResponse ()) {
944
+ $ this ->marshalRequestExceptionWithoutResponse ($ e );
945
+ }
943
946
944
- $ this ->dispatchConnectionFailedEvent ($ request , $ exception );
947
+ if ($ e instanceof RequestException && $ e ->hasResponse ()) {
948
+ $ this ->marshalRequestExceptionWithResponse ($ e );
949
+ }
945
950
946
- throw $ exception ;
951
+ throw $ e ;
947
952
}
948
953
}, $ this ->retryDelay ?? 100 , function ($ exception ) use (&$ shouldRetry ) {
949
954
$ result = $ shouldRetry ?? ($ this ->retryWhenCallback ? call_user_func ($ this ->retryWhenCallback , $ exception , $ this , $ this ->request ?->toPsrRequest()->getMethod ()) : true );
@@ -1517,6 +1522,60 @@ protected function dispatchConnectionFailedEvent(Request $request, ConnectionExc
1517
1522
}
1518
1523
}
1519
1524
1525
+ /**
1526
+ * Handle the given connection exception.
1527
+ *
1528
+ * @param \GuzzleHttp\Exception\ConnectException $e
1529
+ * @return void
1530
+ */
1531
+ protected function marshalConnectionException (ConnectException $ e )
1532
+ {
1533
+ $ exception = new ConnectionException ($ e ->getMessage (), 0 , $ e );
1534
+
1535
+ $ this ->factory ?->recordRequestResponsePair(
1536
+ $ request = new Request ($ e ->getRequest ()), null
1537
+ );
1538
+
1539
+ $ this ->dispatchConnectionFailedEvent ($ request , $ exception );
1540
+
1541
+ throw $ exception ;
1542
+ }
1543
+
1544
+ /**
1545
+ * Handle the given request exception.
1546
+ *
1547
+ * @param \GuzzleHttp\Exception\RequestException $e
1548
+ * @return void
1549
+ */
1550
+ protected function marshalRequestExceptionWithoutResponse (RequestException $ e )
1551
+ {
1552
+ $ exception = new ConnectionException ($ e ->getMessage (), 0 , $ e );
1553
+
1554
+ $ this ->factory ?->recordRequestResponsePair(
1555
+ $ request = new Request ($ e ->getRequest ()), null
1556
+ );
1557
+
1558
+ $ this ->dispatchConnectionFailedEvent ($ request , $ exception );
1559
+
1560
+ throw $ exception ;
1561
+ }
1562
+
1563
+ /**
1564
+ * Handle the given request exception.
1565
+ *
1566
+ * @param \GuzzleHttp\Exception\RequestException $e
1567
+ * @return void
1568
+ */
1569
+ protected function marshalRequestExceptionWithResponse (RequestException $ e )
1570
+ {
1571
+ $ this ->factory ?->recordRequestResponsePair(
1572
+ new Request ($ e ->getRequest ()),
1573
+ $ response = $ this ->populateResponse ($ this ->newResponse ($ e ->getResponse ()))
1574
+ );
1575
+
1576
+ throw $ response ->toException ();
1577
+ }
1578
+
1520
1579
/**
1521
1580
* Set the client instance.
1522
1581
*
0 commit comments