Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-naeka committed Oct 23, 2024
1 parent 70cbc00 commit ae462f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ def call_api_and_store_result(
for criterion in criteria:
criterion.certify(client, save=False)
data_returned_by_api = criterion.data_returned_by_api
# 429, 503 and 504
# See api_particulier.py
if type(data_returned_by_api) is not dict:
data_returned_by_api = {"error": criterion.data_returned_by_api}

if data_returned_by_api.get("status"):
total_criteria_with_certification += 1
Expand Down
16 changes: 7 additions & 9 deletions itou/utils/apis/api_particulier.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ def _request(client, endpoint, job_seeker):
params = _build_params_from(job_seeker=job_seeker)
response = client.get(endpoint, params=params)
error_message = None
# Bad Request or Unauthorized
# Same as 503 except we don't retry
if response.status_code in [400, 401]:
error_message = "Bad Request" if response.status_code == 400 else "Unauthorized"
logger.error(error_message, extra={"errors": response.json().get("errors")})
raise httpx.HTTPStatusError(message=error_message, request=response.request, response=response)
# Too Many Requests
if response.status_code == 429:
elif response.status_code == 429:
errors = response.json().get("errors")
if errors:
error_message = errors[0]
logger.error(error_message)
raise ShouldRetryException(message=error_message, request=response.request, response=response)
# Bad params.
# Same as 503 except we don't retry.
elif response.status_code in (400, 401):
errors = response.json()["errors"]
logger.error(error_message)
raise httpx.HTTPStatusError(message=error_message, request=response.request, response=response)
# Service unavailable
elif response.status_code == 503:
error_message = response.json().get("error")
Expand Down Expand Up @@ -117,8 +117,6 @@ def revenu_solidarite_active(client, job_seeker):
except tenacity.RetryError as retry_err: # 429, 503 or 504
exc = retry_err.last_attempt._exception
data["raw_response"] = exc.response.json()
except KeyError as exc:
data["raw_response"] = str(exc)
else:
data = {
"start_at": _parse_date(data["dateDebut"]),
Expand Down

0 comments on commit ae462f5

Please sign in to comment.