Handle reasons that are None.
Reviewed in https://codereview.appspot.com/7396043/.
This commit is contained in:
@@ -49,6 +49,8 @@ class HttpError(Error):
|
||||
reason = data['error']['message']
|
||||
except (ValueError, KeyError):
|
||||
pass
|
||||
if reason is None:
|
||||
reason = ''
|
||||
return reason
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@@ -91,3 +91,9 @@ class Error(unittest.TestCase):
|
||||
resp, content = fake_response('}NOT OK', {'status':'400'})
|
||||
error = HttpError(resp, content)
|
||||
self.assertEqual(str(error), '<HttpError 400 "Ok">')
|
||||
|
||||
def test_missing_reason(self):
|
||||
"""Test an empty dict with a missing resp.reason."""
|
||||
resp, content = fake_response('}NOT OK', {'status':'400'}, reason=None)
|
||||
error = HttpError(resp, content)
|
||||
self.assertEqual(str(error), '<HttpError 400 "">')
|
||||
|
||||
Reference in New Issue
Block a user