Handle 500 errors coming from nova
We do not want to return the nova error 500 messages to the users but rather build our own message, so that a bug is filled to us. Change-Id: Iaeae2affdb60f22df64fd1929e3bd8c18ac3e64c Closes-bug: #1624233
This commit is contained in:
parent
c83d3efe8b
commit
f9fd5481e3
|
@ -88,16 +88,26 @@ def exception_from_response(response):
|
||||||
501: webob.exc.HTTPNotImplemented,
|
501: webob.exc.HTTPNotImplemented,
|
||||||
503: webob.exc.HTTPServiceUnavailable,
|
503: webob.exc.HTTPServiceUnavailable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message = ('Unexpected API Error. Please report this at '
|
||||||
|
'http://bugs.launchpad.net/ooi/ and attach the ooi '
|
||||||
|
'API log if possible.')
|
||||||
|
|
||||||
code = response.status_int
|
code = response.status_int
|
||||||
exc = exceptions.get(code, webob.exc.HTTPInternalServerError)
|
exc = exceptions.get(code, webob.exc.HTTPInternalServerError)
|
||||||
try:
|
|
||||||
message = response.json_body.popitem()[1].get("message")
|
if code in exceptions:
|
||||||
exc = exc(explanation=message)
|
try:
|
||||||
except Exception:
|
message = response.json_body.popitem()[1].get("message")
|
||||||
LOG.exception("Unknown error happenened processing response %s"
|
except Exception:
|
||||||
% response)
|
LOG.exception("Unknown error happenened processing response %s"
|
||||||
return webob.exc.HTTPInternalServerError()
|
% response)
|
||||||
return exc
|
exc = webob.exc.HTTPInternalServerError
|
||||||
|
else:
|
||||||
|
LOG.error("Nova returned an internal server error %s"
|
||||||
|
% response)
|
||||||
|
|
||||||
|
return exc(explanation=message)
|
||||||
|
|
||||||
|
|
||||||
class BaseHelper(object):
|
class BaseHelper(object):
|
||||||
|
|
|
@ -114,9 +114,6 @@ class TestExceptionHelper(base.TestCase):
|
||||||
429: webob.exc.HTTPTooManyRequests,
|
429: webob.exc.HTTPTooManyRequests,
|
||||||
501: webob.exc.HTTPNotImplemented,
|
501: webob.exc.HTTPNotImplemented,
|
||||||
503: webob.exc.HTTPServiceUnavailable,
|
503: webob.exc.HTTPServiceUnavailable,
|
||||||
# Any other thing should be a 500
|
|
||||||
500: webob.exc.HTTPInternalServerError,
|
|
||||||
507: webob.exc.HTTPInternalServerError,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for code, exception in six.iteritems(code_and_exception):
|
for code, exception in six.iteritems(code_and_exception):
|
||||||
|
@ -126,6 +123,23 @@ class TestExceptionHelper(base.TestCase):
|
||||||
self.assertIsInstance(ret, exception)
|
self.assertIsInstance(ret, exception)
|
||||||
self.assertEqual(fault["computeFault"]["message"], ret.explanation)
|
self.assertEqual(fault["computeFault"]["message"], ret.explanation)
|
||||||
|
|
||||||
|
def test_unexpected_exception(self):
|
||||||
|
code_and_exception = {
|
||||||
|
500: webob.exc.HTTPInternalServerError,
|
||||||
|
# Any other thing should be a 500
|
||||||
|
507: webob.exc.HTTPInternalServerError,
|
||||||
|
}
|
||||||
|
message = ("Unexpected API Error. Please report this at "
|
||||||
|
"http://bugs.launchpad.net/ooi/ and attach the "
|
||||||
|
"ooi API log if possible.")
|
||||||
|
|
||||||
|
for code, exception in six.iteritems(code_and_exception):
|
||||||
|
fault = self.get_fault(code)
|
||||||
|
resp = fakes.create_fake_json_resp(fault, code)
|
||||||
|
ret = helpers.exception_from_response(resp)
|
||||||
|
self.assertIsInstance(ret, exception)
|
||||||
|
self.assertEqual(message, ret.explanation)
|
||||||
|
|
||||||
def test_error_handling_exception(self):
|
def test_error_handling_exception(self):
|
||||||
fault = {}
|
fault = {}
|
||||||
resp = fakes.create_fake_json_resp(fault, 404)
|
resp = fakes.create_fake_json_resp(fault, 404)
|
||||||
|
|
Loading…
Reference in New Issue