From a5d698db9c7eaa00eef171a2ce3a250a093b6278 Mon Sep 17 00:00:00 2001 From: Tamar Ben-Shachar Date: Fri, 26 Jun 2015 17:34:58 -0700 Subject: [PATCH] dcos-1886 don't crash if invalid json commands --- cli/tests/integrations/test_marathon.py | 10 ++++++++++ dcos/marathon.py | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/cli/tests/integrations/test_marathon.py b/cli/tests/integrations/test_marathon.py index 788f537..880296b 100644 --- a/cli/tests/integrations/test_marathon.py +++ b/cli/tests/integrations/test_marathon.py @@ -361,6 +361,16 @@ def test_update_bad_type(): assert stdout == b'' +def test_update_invalid_request(): + returncode, stdout, stderr = exec_command( + ['dcos', 'marathon', 'app', 'update', '{', 'instances']) + assert returncode == 1 + assert stdout == b'' + stderr = stderr.decode() + assert stderr.startswith('Error while fetching') + assert stderr.endswith('HTTP 400: Bad Request\n') + + def test_update_app(): with _zero_instance_app(): returncode, stdout, stderr = exec_command( diff --git a/dcos/marathon.py b/dcos/marathon.py index 6769de3..f0888a4 100644 --- a/dcos/marathon.py +++ b/dcos/marathon.py @@ -54,6 +54,11 @@ def _to_exception(response): if isinstance(response, Exception): return DCOSException(_default_marathon_error(str(response))) + if response.status_code == 400: + return DCOSException( + 'Error while fetching [{0}]: HTTP {1}: {2}'.format( + response.request.url, response.status_code, response.reason)) + message = response.json().get('message') if message is None: errs = response.json().get('errors')