Skip to content

Commit

Permalink
Always return the response json in request_post
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Jan 9, 2024
1 parent 54492ca commit c7599f5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dejacode_toolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,18 @@ def request_get(self, url, **kwargs):
logger.error(f"{self.label} [Exception] {exception}")

def request_post(self, url, **kwargs):
"""
Return the response from calling URL using current session.
Return `None` in case of Exception.
"""
"""Return the response from a HTTP POST request on the provided `url` ."""
if "timeout" not in kwargs:
kwargs["timeout"] = self.default_timeout

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 c7599f5

Please sign in to comment.