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,20 +87,27 @@ class PartenaireRomeAppellation
{ {
$bearer = $this->getBearer(); $bearer = $this->getBearer();
try { while (true) {
$response = $this->httpClient->request('GET', sprintf(self::BASE.'appellation/%s', $code), [ try {
'headers' => [ $response = $this->httpClient->request('GET', sprintf(self::BASE.'appellation/%s', $code), [
'Authorization' => 'Bearer '.$bearer, 'headers' => [
'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $bearer,
], 'Accept' => 'application/json',
'query' => [ ],
'champs' => 'code,libelle,metier(code,libelle)', 'query' => [
], 'champs' => 'code,libelle,metier(code,libelle)',
]); ],
]);
return $response->toArray(); return $response->toArray();
} catch (HttpExceptionInterface $exception) { } catch (HttpExceptionInterface $exception) {
throw $exception; if ($exception->getResponse()->getStatusCode() === 429) {
$retryAfter = $exception->getResponse()->getHeaders(false)['retry-after'][0] ?? 1;
sleep((int)$retryAfter);
} else {
throw $exception;
}
}
} }
} }
} }