From a633e2fd8e74b8c4dae0b1723f1587358b5f4cab Mon Sep 17 00:00:00 2001 From: tdruez Date: Tue, 9 Jan 2024 18:11:30 -0700 Subject: [PATCH] Fix the request_post to properly catch all exceptions Signed-off-by: tdruez --- dejacode_toolkit/__init__.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dejacode_toolkit/__init__.py b/dejacode_toolkit/__init__.py index 86db8dfd..7b121f7e 100644 --- a/dejacode_toolkit/__init__.py +++ b/dejacode_toolkit/__init__.py @@ -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}")