Skip to content

Commit 2a8d294

Browse files
committed
Retry helper
1 parent d91a365 commit 2a8d294

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=5.4.0",
14-
"illuminate/support": "5.*|6.*|7.*|8.*|9.*",
13+
"php": ">=7.3",
14+
"illuminate/support": "8.*|9.*",
1515
"guzzlehttp/guzzle": "^6.2|^7.0|^7.4",
1616
"artisaninweb/laravel-soap": "^0.3"
1717
},

src/Utils/Request.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ public function doRequest($method, $path, $options = [])
8181
// silence hooks!!!
8282
}
8383

84+
if (filter_var(config('economic.retry_server_exceptions.enabled'), FILTER_VALIDATE_BOOLEAN)) {
85+
return retry(config('economic.retry_server_exceptions.retries', 3), function () use ($method, $path, $options) {
86+
return $this->curl->{$method}($path, $options);
87+
}, config('economic.retry_server_exceptions.timeout_ms', 10000), function (\Throwable $throwable) { return $throwable->getCode() >= 500 && $throwable->getCode() <= 599; });
88+
}
89+
8490
return $this->curl->{$method}($path, $options);
8591
}
8692
}

src/config/economic.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,13 @@
1111
* Automatically strip null values.
1212
* ----------------------------------------------------- */
1313
'strip_null' => true,
14+
15+
/* --------------------------------------------------------
16+
* Automatically retry requests for server exceptions (5XX)
17+
* ----------------------------------------------------- */
18+
'retry_server_exceptions' => [
19+
'enabled' => false,
20+
'retries' => 3,
21+
'timeout_ms' => 10000,
22+
]
1423
];

0 commit comments

Comments
 (0)