Return full error message for HTTP errors

Non-HeatException, non-remote errors were getting their messages
truncated at the first newline and leaving incomplete error messages the
in json response.  We can only be certain that remote errors raised
through oslo.messaging will conform to the "message + \n + stack_trace"
formula

Closes-Bug: #1358417
Change-Id: I785c6e41101960ea7ceb00c0733c49c2a8aa909f
This commit is contained in:
Richard Lee 2014-08-18 15:28:25 -05:00
parent 531e95a6cc
commit d2f4a6b1ed
2 changed files with 22 additions and 2 deletions

View File

@ -108,11 +108,12 @@ class FaultWrapper(wsgi.Middleware):
ex_type = ex.__class__.__name__
if ex_type.endswith('_Remote'):
is_remote = ex_type.endswith('_Remote')
if is_remote:
ex_type = ex_type[:-len('_Remote')]
full_message = unicode(ex)
if full_message.find('\n') > -1:
if full_message.find('\n') > -1 and is_remote:
message, msg_trace = full_message.split('\n', 1)
else:
msg_trace = traceback.format_exc()

View File

@ -13,6 +13,7 @@
from oslo.config import cfg
import six
import webob
from oslo.messaging._drivers import common as rpc_common
@ -25,8 +26,26 @@ class StackNotFoundChild(heat_exc.StackNotFound):
pass
class ErrorWithNewline(webob.exc.HTTPBadRequest):
pass
class FaultMiddlewareTest(HeatTestCase):
def test_disguised_http_exception_with_newline(self):
wrapper = fault.FaultWrapper(None)
newline_error = ErrorWithNewline('Error with \n newline')
msg = wrapper._error(heat_exc.HTTPExceptionDisguise(newline_error))
expected = {'code': 400,
'error': {'message': 'Error with \n newline',
'traceback': None,
'type': 'ErrorWithNewline'},
'explanation': ('The server could not comply with the '
'request since it is either malformed '
'or otherwise incorrect.'),
'title': 'Bad Request'}
self.assertEqual(expected, msg)
def test_openstack_exception_with_kwargs(self):
wrapper = fault.FaultWrapper(None)
msg = wrapper._error(heat_exc.StackNotFound(stack_name='a'))