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 six
|
||||
|
||||
from magnum.i18n import _
|
||||
|
||||
|
@ -57,7 +58,8 @@ class ParsableErrorMiddleware(object):
|
|||
|
||||
app_iter = self.app(environ, replacement_start_response)
|
||||
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-Length', str(len(body[0]))))
|
||||
else:
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import six
|
||||
|
||||
import mock
|
||||
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
|
||||
# rare thing (happens due to wrong deserialization settings etc.)
|
||||
# we don't care about this garbage.
|
||||
expected_msg = ("Remote error: %s %s"
|
||||
% (test_exc_type, self.MSG_WITHOUT_TRACE) + "\n[u'")
|
||||
if six.PY2:
|
||||
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']
|
||||
self.assertEqual(expected_msg, actual_msg)
|
||||
|
||||
|
|
Loading…
Reference in New Issue