Skip to content

Commit

Permalink
Fix unprintable message with BatchError repr (googleapis#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
ittus authored and nathanielmanistaatgoogle committed Oct 31, 2016
1 parent df61397 commit 5f00cad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions googleapiclient/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def __init__(self, reason, resp=None, content=None):
self.reason = reason

def __repr__(self):
if getattr(self.resp, 'status', None) is None:
return '<BatchError "%s">' % (self.reason)
else:
return '<BatchError %s "%s">' % (self.resp.status, self.reason)

__str__ = __repr__
Expand Down
4 changes: 3 additions & 1 deletion tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,9 @@ def test_add_fail_for_resumable(self):
upload = MediaFileUpload(
datafile('small.png'), chunksize=500, resumable=True)
self.request1.resumable = upload
self.assertRaises(BatchError, batch.add, self.request1, request_id='1')
with self.assertRaises(BatchError) as batch_error:
batch.add(self.request1, request_id='1')
str(batch_error.exception)

def test_execute_empty_batch_no_http(self):
batch = BatchHttpRequest()
Expand Down

0 comments on commit 5f00cad

Please sign in to comment.