Merge "handle bytes list in api middleware"
This commit is contained in:
commit
a4b766da09
|
@ -19,6 +19,7 @@ Based on pecan.middleware.errordocument
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import six
|
||||||
|
|
||||||
from magnum.i18n import _
|
from magnum.i18n import _
|
||||||
|
|
||||||
|
@ -57,7 +58,8 @@ class ParsableErrorMiddleware(object):
|
||||||
|
|
||||||
app_iter = self.app(environ, replacement_start_response)
|
app_iter = self.app(environ, replacement_start_response)
|
||||||
if (state['status_code'] // 100) not in (2, 3):
|
if (state['status_code'] // 100) not in (2, 3):
|
||||||
body = [json.dumps({'error_message': '\n'.join(app_iter)})]
|
body = [six.b(json.dumps({'error_message':
|
||||||
|
six.b('\n').join(app_iter).decode('utf-8')}))]
|
||||||
state['headers'].append(('Content-Type', 'application/json'))
|
state['headers'].append(('Content-Type', 'application/json'))
|
||||||
state['headers'].append(('Content-Length', str(len(body[0]))))
|
state['headers'].append(('Content-Length', str(len(body[0]))))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import six
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
@ -104,8 +105,13 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest):
|
||||||
# instead of'\n'.join(trace). But since RemoteError is kind of very
|
# instead of'\n'.join(trace). But since RemoteError is kind of very
|
||||||
# rare thing (happens due to wrong deserialization settings etc.)
|
# rare thing (happens due to wrong deserialization settings etc.)
|
||||||
# we don't care about this garbage.
|
# we don't care about this garbage.
|
||||||
expected_msg = ("Remote error: %s %s"
|
if six.PY2:
|
||||||
% (test_exc_type, self.MSG_WITHOUT_TRACE) + "\n[u'")
|
expected_msg = ("Remote error: %s %s"
|
||||||
|
% (test_exc_type, self.MSG_WITHOUT_TRACE)
|
||||||
|
+ "\n[u'")
|
||||||
|
else:
|
||||||
|
expected_msg = ("Remote error: %s %s"
|
||||||
|
% (test_exc_type, self.MSG_WITHOUT_TRACE) + "\n['")
|
||||||
actual_msg = json.loads(response.json['error_message'])['faultstring']
|
actual_msg = json.loads(response.json['error_message'])['faultstring']
|
||||||
self.assertEqual(expected_msg, actual_msg)
|
self.assertEqual(expected_msg, actual_msg)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue