Repository: google/google-api-python-client (python)

Issue:
BatchError is unprintable using default constructor (one string)
This one should be pretty simple, I hope.

Here's the constructor signature: `def __init__(self, reason, resp=None, content=None):`, which doesn't require `resp` to be defined, and I can see it is not defined most of the time, for example, in googleapiclient/http.py.

Then, given the representation method:

```
def __repr__(self):
      return '<BatchError %s "%s">' % (self.resp.status, self.reason)
```

Which is also the string method:

```
__str__ = __repr__
```

This results in unprintable exceptions where `resp` is undefined, which is not very helpful when attempting to understand the error (e.g. #164).


Pull request description:
BatchError is unprintable using default constructor (#165)
Fix #165 


Patch:
diff --git a/googleapiclient/errors.py b/googleapiclient/errors.py
index e6f1f9d45..6a741f86d 100644
--- a/googleapiclient/errors.py
+++ b/googleapiclient/errors.py
@@ -126,6 +126,9 @@ class BatchError(HttpError):
     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__


Test patch:
diff --git a/tests/test_http.py b/tests/test_http.py
index 865d84703..36b43bf16 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -1053,7 +1053,9 @@ class TestBatch(unittest.TestCase):
     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()