summaryrefslogtreecommitdiff
path: root/swiftclient/exceptions.py
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2020-08-14 10:41:15 -0700
committerTim Burke <tim.burke@gmail.com>2020-09-09 15:32:43 -0700
commit0f6713ed5b8cdcf5cbc0850dea224b41d90e63f4 (patch)
tree80f8b277aa2b91a4606e9d7b30d7f1742361b182 /swiftclient/exceptions.py
parent9d8db8f6126542dc18ea1b14e078d64cc1a254e4 (diff)
downloadpython-swiftclient-0f6713ed5b8cdcf5cbc0850dea224b41d90e63f4.tar.gz
Include transaction ID in ClientException.__str__
It's fairly annoying getting a traceback in swift's probe tests then only having a URL and status code to go searching for in logs. Leave the shell.py output untouched, though, since we output the transaction ID on a new line anyway. Change-Id: Idb849848ec08b6c04812b088467c9a687c2a7e27
Diffstat (limited to 'swiftclient/exceptions.py')
-rw-r--r--swiftclient/exceptions.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/swiftclient/exceptions.py b/swiftclient/exceptions.py
index da70379..a9b993c 100644
--- a/swiftclient/exceptions.py
+++ b/swiftclient/exceptions.py
@@ -35,6 +35,13 @@ class ClientException(Exception):
self.http_response_content = http_response_content
self.http_response_headers = http_response_headers
+ self.transaction_id = None
+ if self.http_response_headers:
+ for header in ('X-Trans-Id', 'X-Openstack-Request-Id'):
+ if header in self.http_response_headers:
+ self.transaction_id = self.http_response_headers[header]
+ break
+
@classmethod
def from_response(cls, resp, msg=None, body=None):
msg = msg or '%s %s' % (resp.status_code, resp.reason)
@@ -78,4 +85,7 @@ class ClientException(Exception):
else:
b += ' [first 60 chars of response] %s' \
% self.http_response_content[:60]
- return b and '%s: %s' % (a, b) or a
+ c = ''
+ if self.transaction_id:
+ c = ' (txn: %s)' % self.transaction_id
+ return b and '%s: %s%s' % (a, b, c) or (a + c)