Fix request to France Travail Api to accomodate for new request limit

A new limit was set to allow a maximum amount of request in a certain timeframe. We need to wait 1 sec to make next request.
This commit is contained in:
Julie Lenaerts 2024-07-15 15:11:34 +02:00
parent 00ceee1fd5
commit b100792a34

View File

@ -87,6 +87,7 @@ class PartenaireRomeAppellation
{ {
$bearer = $this->getBearer(); $bearer = $this->getBearer();
while (true) {
try { try {
$response = $this->httpClient->request('GET', sprintf(self::BASE.'appellation/%s', $code), [ $response = $this->httpClient->request('GET', sprintf(self::BASE.'appellation/%s', $code), [
'headers' => [ 'headers' => [
@ -100,7 +101,13 @@ class PartenaireRomeAppellation
return $response->toArray(); return $response->toArray();
} catch (HttpExceptionInterface $exception) { } catch (HttpExceptionInterface $exception) {
if ($exception->getResponse()->getStatusCode() === 429) {
$retryAfter = $exception->getResponse()->getHeaders(false)['retry-after'][0] ?? 1;
sleep((int)$retryAfter);
} else {
throw $exception; throw $exception;
} }
} }
} }
}
}