dcos-1886 don't crash if invalid json commands

This commit is contained in:
Tamar Ben-Shachar
2015-06-26 17:34:58 -07:00
parent 14b3c8e5f6
commit a5d698db9c
2 changed files with 15 additions and 0 deletions

View File

@@ -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(

View File

@@ -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')