From e405cb3f447dffbcd6665de93334274d7149f3b2 Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes <kiall@hp.com> Date: Mon, 14 Oct 2013 12:45:19 +0100 Subject: [PATCH] Ensure Invalid JSON and errors during deletes are displayed correctly Change-Id: Iccd4ee10611cfa58a98618f29545d5b194edafa3 --- designateclient/cli/base.py | 5 +++-- designateclient/v1/__init__.py | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/designateclient/cli/base.py b/designateclient/cli/base.py index 87582029..16673f17 100644 --- a/designateclient/cli/base.py +++ b/designateclient/cli/base.py @@ -122,5 +122,6 @@ class UpdateCommand(Command, ShowOne): return results.keys(), results.values() -class DeleteCommand(Command): - pass +class DeleteCommand(Command, ShowOne): + def post_execute(self, results): + return [], [] diff --git a/designateclient/v1/__init__.py b/designateclient/v1/__init__.py index e3604cee..e388730f 100644 --- a/designateclient/v1/__init__.py +++ b/designateclient/v1/__init__.py @@ -88,16 +88,22 @@ class Client(object): # Trigger the request response = func(*args, **kw) + # Decode is response, if possible + try: + response_payload = response.json() + except ValueError: + response_payload = {} + if response.status_code == 400: - raise exceptions.BadRequest(**response.json()) + raise exceptions.BadRequest(**response_payload) elif response.status_code in (401, 403): - raise exceptions.Forbidden(**response.json()) + raise exceptions.Forbidden(**response_payload) elif response.status_code == 404: - raise exceptions.NotFound(**response.json()) + raise exceptions.NotFound(**response_payload) elif response.status_code == 409: - raise exceptions.Conflict(**response.json()) - elif response.status_code == 500: - raise exceptions.Unknown(**response.json()) + raise exceptions.Conflict(**response_payload) + elif response.status_code >= 500: + raise exceptions.Unknown(**response_payload) else: return response