diff --git a/dejacode_toolkit/__init__.py b/dejacode_toolkit/__init__.py index 464f2d32..86db8dfd 100644 --- a/dejacode_toolkit/__init__.py +++ b/dejacode_toolkit/__init__.py @@ -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}")