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