Skip to content

Commit e7bbbb9

Browse files
committed
Handle reasons that are None.
Reviewed in https://codereview.appspot.com/7396043/.
1 parent 003b6e4 commit e7bbbb9

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

apiclient/errors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def _get_reason(self):
4949
reason = data['error']['message']
5050
except (ValueError, KeyError):
5151
pass
52+
if reason is None:
53+
reason = ''
5254
return reason
5355

5456
def __repr__(self):

tests/test_errors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,9 @@ def test_non_json(self):
9191
resp, content = fake_response('}NOT OK', {'status':'400'})
9292
error = HttpError(resp, content)
9393
self.assertEqual(str(error), '<HttpError 400 "Ok">')
94+
95+
def test_missing_reason(self):
96+
"""Test an empty dict with a missing resp.reason."""
97+
resp, content = fake_response('}NOT OK', {'status':'400'}, reason=None)
98+
error = HttpError(resp, content)
99+
self.assertEqual(str(error), '<HttpError 400 "">')

0 commit comments

Comments
 (0)