Skip to content

Commit

Permalink
Improve Content-Type handling in exception handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Mar 29, 2022
1 parent 9ee0924 commit b110513
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
History
-------

2.7.2 (2022-03-29)
++++++++++++++++++

* Updated code to correctly handle ``None`` ``Content-Type`` from minFraud
web service. This should never happen, but if it does, the correct
exception will now be thrown.

2.7.1 (2022-03-29)
++++++++++++++++++

Expand Down
6 changes: 3 additions & 3 deletions minfraud/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _handle_success(
return model_class(decoded_body) # type: ignore

def _exception_for_error(
self, status: int, content_type: str, raw_body: str, uri: str
self, status: int, content_type: Optional[str], raw_body: str, uri: str
) -> Union[
AuthenticationError,
InsufficientFundsError,
Expand All @@ -100,7 +100,7 @@ def _exception_for_error(
return self._exception_for_unexpected_status(status, raw_body, uri)

def _exception_for_4xx_status(
self, status: int, content_type: str, raw_body: str, uri: str
self, status: int, content_type: Optional[str], raw_body: str, uri: str
) -> Union[
AuthenticationError,
InsufficientFundsError,
Expand All @@ -113,7 +113,7 @@ def _exception_for_4xx_status(
return HTTPError(
f"Received a {status} error with no body", status, uri, raw_body
)
if content_type.find("json") == -1:
if content_type is None or content_type.find("json") == -1:
return HTTPError(
f"Received a {status} with the following body: {raw_body}",
status,
Expand Down

0 comments on commit b110513

Please sign in to comment.