Handle reasons that are None.

Reviewed in https://codereview.appspot.com/7396043/.
This commit is contained in:
Joe Gregorio
2013-02-20 15:37:24 -05:00
parent 003b6e4aa4
commit e7bbbb94d0
2 changed files with 8 additions and 0 deletions

View File

@@ -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):

View File

@@ -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 "">')