fix: AW-2 json() returns None on a non-UTF-8 body instead of raising
responses.json() catches UnicodeDecodeError alongside JSONDecodeError — text() can raise it on a non-UTF-8 payload, which is a 'not valid JSON' outcome per the docstring, not an error to propagate. Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
parent
3737af0cf5
commit
14a3ee1456
@ -92,7 +92,9 @@ class Response:
|
||||
"""parsed JSON content, or None if not valid JSON"""
|
||||
try:
|
||||
return _json.loads(self.text())
|
||||
except _json.JSONDecodeError:
|
||||
except (_json.JSONDecodeError, UnicodeDecodeError):
|
||||
# text() decodes the body and can raise UnicodeDecodeError on a non-UTF-8
|
||||
# payload — that's a "not valid JSON" outcome, not an error to propagate
|
||||
return None
|
||||
|
||||
def raise_for_status(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user