Skip to content

Commit b110513

Browse files
committed
Improve Content-Type handling in exception handling code
1 parent 9ee0924 commit b110513

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

HISTORY.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
History
44
-------
55

6+
2.7.2 (2022-03-29)
7+
++++++++++++++++++
8+
9+
* Updated code to correctly handle ``None`` ``Content-Type`` from minFraud
10+
web service. This should never happen, but if it does, the correct
11+
exception will now be thrown.
12+
613
2.7.1 (2022-03-29)
714
++++++++++++++++++
815

minfraud/webservice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _handle_success(
8383
return model_class(decoded_body) # type: ignore
8484

8585
def _exception_for_error(
86-
self, status: int, content_type: str, raw_body: str, uri: str
86+
self, status: int, content_type: Optional[str], raw_body: str, uri: str
8787
) -> Union[
8888
AuthenticationError,
8989
InsufficientFundsError,
@@ -100,7 +100,7 @@ def _exception_for_error(
100100
return self._exception_for_unexpected_status(status, raw_body, uri)
101101

102102
def _exception_for_4xx_status(
103-
self, status: int, content_type: str, raw_body: str, uri: str
103+
self, status: int, content_type: Optional[str], raw_body: str, uri: str
104104
) -> Union[
105105
AuthenticationError,
106106
InsufficientFundsError,
@@ -113,7 +113,7 @@ def _exception_for_4xx_status(
113113
return HTTPError(
114114
f"Received a {status} error with no body", status, uri, raw_body
115115
)
116-
if content_type.find("json") == -1:
116+
if content_type is None or content_type.find("json") == -1:
117117
return HTTPError(
118118
f"Received a {status} with the following body: {raw_body}",
119119
status,

0 commit comments

Comments
 (0)