Fix unprintable message with BatchError repr (#165)
diff --git a/googleapiclient/errors.py b/googleapiclient/errors.py
index e6f1f9d..6a741f8 100644
--- a/googleapiclient/errors.py
+++ b/googleapiclient/errors.py
@@ -126,6 +126,9 @@
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__
diff --git a/tests/test_http.py b/tests/test_http.py
index 865d847..36b43bf 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -1053,7 +1053,9 @@
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()