Report transaction ID in failure exceptions

This way, when something fails in Jenkins, you have some chance of
searching the logs for the relevant transaction.

Change-Id: I3cf606cb4963e32b5c6ac3deda08e73541b3ff7d
This commit is contained in:
Samuel Merritt 2013-11-27 17:23:59 -08:00
parent 7cc009735a
commit 8a64bff2dc

View File

@ -45,14 +45,23 @@ class ResponseError(Exception):
self.reason = response.reason self.reason = response.reason
self.method = method self.method = method
self.path = path self.path = path
self.headers = response.getheaders()
for name, value in self.headers:
if name.lower() == 'x-trans-id':
self.txid = value
break
else:
self.txid = None
super(ResponseError, self).__init__() super(ResponseError, self).__init__()
def __str__(self): def __str__(self):
return repr(self) return repr(self)
def __repr__(self): def __repr__(self):
return '%d: %r (%r %r)' % (self.status, self.reason, self.method, return '%d: %r (%r %r) txid=%s' % (
self.path) self.status, self.reason, self.method, self.path, self.txid)
def listing_empty(method): def listing_empty(method):