File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 3
3
## 2.0 (unreleased)
4
4
5
5
### Changed
6
+ - RetryPlugin will no longer retry requests when the response failed with a HTTP code < 500.
6
7
- Abstract method ` HttpClientPool::chooseHttpClient() ` has now an explicit return type (` Http\Client\Common\HttpClientPoolItem ` )
7
8
- Interface method ` Plugin::handleRequest(...) ` has now an explicit return type (` Http\Promise\Promise ` )
8
9
Original file line number Diff line number Diff line change @@ -59,6 +59,28 @@ public function it_throws_exception_on_multiple_exceptions(RequestInterface $req
59
59
$ promise ->shouldThrow ($ exception2 )->duringWait ();
60
60
}
61
61
62
+ public function it_does_not_retry_client_errors (RequestInterface $ request , ResponseInterface $ response )
63
+ {
64
+ $ exception = new Exception \HttpException ('Exception ' , $ request ->getWrappedObject (), $ response ->getWrappedObject ());
65
+
66
+ $ seen = false ;
67
+ $ next = function (RequestInterface $ receivedRequest ) use ($ request , $ exception , &$ seen ) {
68
+ if (!Argument::is ($ request ->getWrappedObject ())->scoreArgument ($ receivedRequest )) {
69
+ throw new \Exception ('Unexpected request received ' );
70
+ }
71
+ if ($ seen ) {
72
+ throw new \Exception ('This should only be called once ' );
73
+ }
74
+ $ seen = true ;
75
+
76
+ return new HttpRejectedPromise ($ exception );
77
+ };
78
+
79
+ $ promise = $ this ->handleRequest ($ request , $ next , function () {});
80
+ $ promise ->shouldReturnAnInstanceOf (HttpRejectedPromise::class);
81
+ $ promise ->shouldThrow ($ exception )->duringWait ();
82
+ }
83
+
62
84
public function it_returns_response_on_second_try (RequestInterface $ request , ResponseInterface $ response )
63
85
{
64
86
$ exception = new Exception \NetworkException ('Exception 1 ' , $ request ->getWrappedObject ());
Original file line number Diff line number Diff line change 4
4
5
5
use Http \Client \Common \Plugin ;
6
6
use Http \Client \Exception ;
7
+ use Http \Client \Exception \HttpException ;
7
8
use Http \Promise \Promise ;
8
9
use Psr \Http \Message \RequestInterface ;
9
10
use Psr \Http \Message \ResponseInterface ;
@@ -56,7 +57,8 @@ public function __construct(array $config = [])
56
57
$ resolver ->setDefaults ([
57
58
'retries ' => 1 ,
58
59
'decider ' => function (RequestInterface $ request , Exception $ e ) {
59
- return true ;
60
+ // do not retry client errors
61
+ return !$ e instanceof HttpException || $ e ->getCode () >= 500 ;
60
62
},
61
63
'delay ' => __CLASS__ .'::defaultDelay ' ,
62
64
]);
You can’t perform that action at this time.
0 commit comments