Skip to content

Commit

Permalink
[FIX] delivery_postlogistics: raise exception when no token received
Browse files Browse the repository at this point in the history
Sometimes due to API error it may happen we don't receive anything back when requesting token.
In this case we want to show meaningful message.
  • Loading branch information
ajaniszewska-dev committed Oct 29, 2024
1 parent 85bdccb commit 3470491
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion delivery_postlogistics/postlogistics/web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,20 @@ def _request_access_token(cls, delivery_carrier):
},
timeout=60,
)
return response.json()

response.raise_for_status()

try:
json_response = response.json()
except requests.exceptions.JSONDecodeError as exc:

Check warning on line 458 in delivery_postlogistics/postlogistics/web_service.py

View check run for this annotation

Codecov / codecov/patch

delivery_postlogistics/postlogistics/web_service.py#L458

Added line #L458 was not covered by tests
if not json_response:
raise exceptions.UserError(

Check warning on line 460 in delivery_postlogistics/postlogistics/web_service.py

View check run for this annotation

Codecov / codecov/patch

delivery_postlogistics/postlogistics/web_service.py#L460

Added line #L460 was not covered by tests
_("API response without content - no access token received.")
) from exc
raise

Check warning on line 463 in delivery_postlogistics/postlogistics/web_service.py

View check run for this annotation

Codecov / codecov/patch

delivery_postlogistics/postlogistics/web_service.py#L463

Added line #L463 was not covered by tests

_logger.debug("JSON Response: %s" % json_response)
return json_response

@classmethod
def get_access_token(cls, picking_carrier):
Expand Down

0 comments on commit 3470491

Please sign in to comment.