Skip to content

Commit

Permalink
Fix the request_post to properly catch all exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jan 10, 2024
1 parent c7599f5 commit a633e2f
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions dejacode_toolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,10 @@ def request_post(self, url, **kwargs):
if "timeout" not in kwargs:
kwargs["timeout"] = self.default_timeout

# Do not `raise_for_status` as the response may contain valuable data
# even on non 200 status code.
try:
response = self.session.post(url, **kwargs)
response.raise_for_status()
except requests.HTTPError as error:
logger.error(f"{self.label} [HTTPError] {error}")

# The response may contain valuable data even on non 200 status code.
try:
return response.json()
except (requests.RequestException, ValueError, TypeError) as exception:
logger.error(f"{self.label} [Exception] {exception}")

0 comments on commit a633e2f

Please sign in to comment.