summaryrefslogtreecommitdiff
path: root/swiftclient/shell.py
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2016-01-18 17:05:28 -0800
committerTim Burke <tim.burke@gmail.com>2016-03-03 17:16:33 +0000
commit9b8ab67a780416508b995adafb07e96ea646d6f8 (patch)
treee8b1b580a0e2e2d9dc941924f408966da4ffdfe5 /swiftclient/shell.py
parentcd3a4dbf0adce0b7a6779755caaf36a0e983e5fb (diff)
downloadpython-swiftclient-9b8ab67a780416508b995adafb07e96ea646d6f8.tar.gz
Include response headers in ClientExceptions
Now, client applications can get to things like transaction IDs for failures without needing to turn on all of logging. While we're at it, add a from_response factory method for ClientException. Co-Authored-By: Alexander Corwin <ancorwin@gmail.com> Change-Id: Ib46d5f8fc7f36f651f5908bb9d900316fdaebce3
Diffstat (limited to 'swiftclient/shell.py')
-rwxr-xr-xswiftclient/shell.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index 15be20a..68b9344 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -33,7 +33,8 @@ from swiftclient.utils import config_true_value, generate_temp_url, prt_bytes
from swiftclient.multithreading import OutputManager
from swiftclient.exceptions import ClientException
from swiftclient import __version__ as client_version
-from swiftclient.client import logger_settings as client_logger_settings
+from swiftclient.client import logger_settings as client_logger_settings, \
+ parse_header_string
from swiftclient.service import SwiftService, SwiftError, \
SwiftUploadObject, get_conn
from swiftclient.command_helpers import print_account_stats, \
@@ -1475,7 +1476,13 @@ Examples:
parser.usage = globals()['st_%s_help' % args[0]]
try:
globals()['st_%s' % args[0]](parser, argv[1:], output)
- except (ClientException, RequestException, socket.error) as err:
+ except ClientException as err:
+ output.error(str(err))
+ trans_id = (err.http_response_headers or {}).get('X-Trans-Id')
+ if trans_id:
+ output.error("Failed Transaction ID: %s",
+ parse_header_string(trans_id))
+ except (RequestException, socket.error) as err:
output.error(str(err))
if output.get_error_count() > 0: