You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Plugin/RetryPlugin.php
+92-20Lines changed: 92 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -29,12 +29,22 @@ final class RetryPlugin implements Plugin
29
29
/**
30
30
* @var callable
31
31
*/
32
-
private$delay;
32
+
private$errorResponseDecider;
33
33
34
34
/**
35
35
* @var callable
36
36
*/
37
-
private$decider;
37
+
private$exceptionDecider;
38
+
39
+
/**
40
+
* @var callable
41
+
*/
42
+
private$errorResponseDelay;
43
+
44
+
/**
45
+
* @var callable
46
+
*/
47
+
private$exceptionDelay;
38
48
39
49
/**
40
50
* Store the retry counter for each request.
@@ -47,29 +57,60 @@ final class RetryPlugin implements Plugin
47
57
* @param array $config {
48
58
*
49
59
* @var int $retries Number of retries to attempt if an exception occurs before letting the exception bubble up
50
-
* @var callable $decider A callback that gets a request and an exception to decide after a failure whether the request should be retried
51
-
* @var callable $delay A callback that gets a request, an exception and the number of retries and returns how many microseconds we should wait before trying again.
60
+
* @var callable $error_response_decider A callback that gets a request and response to decide whether the request should be retried
61
+
* @var callable $exception_decider A callback that gets a request and an exception to decide after a failure whether the request should be retried
62
+
* @var callable $error_response_delay A callback that gets a request and response and the number of retries and returns how many microseconds we should wait before trying again
63
+
* @var callable $exception_delay A callback that gets a request, an exception and the number of retries and returns how many microseconds we should wait before trying again
52
64
* }
65
+
*
66
+
* @since exception_decider and error_response_decider have been added in version 2. In version 1.*, the exception_decider has been called decider.
53
67
*/
54
68
publicfunction__construct(array$config = [])
55
69
{
56
70
$resolver = newOptionsResolver();
57
71
$resolver->setDefaults([
58
72
'retries' => 1,
59
-
'decider' => function (RequestInterface$request, Exception$e) {
73
+
'error_response_decider' => function (RequestInterface$request, ResponseInterface$response) {
74
+
// do not retry client errors
75
+
return$response->getStatusCode() >= 500;
76
+
},
77
+
'exception_decider' => function (RequestInterface$request, Exception$e) {
0 commit comments