Merge "Change nailgun error handling to json-compatible"

This commit is contained in:
Jenkins
2015-03-04 19:17:05 +00:00
committed by Gerrit Code Review

View File

@@ -13,6 +13,7 @@
# under the License.
from functools import wraps
import json
from keystoneclient.exceptions import Unauthorized
import requests
import sys
@@ -99,8 +100,7 @@ def exceptions_decorator(func):
# when server returns to us bad request check that
# and print meaningful reason
except requests.HTTPError as exc:
error_body = exc.response.text
exit_with_error("{0} ({1})".format(exc, error_body))
exit_with_error("{0} ({1})".format(exc, get_error_body(exc)))
except requests.ConnectionError:
exit_with_error("""
Can't connect to Nailgun server!
@@ -120,3 +120,12 @@ def exceptions_decorator(func):
return {}
return wrapper
def get_error_body(error):
try:
error_body = json.loads(error.response.text)['message']
except (ValueError, TypeError, KeyError):
error_body = error.response.text
return error_body