Ensure the correct error message is displayed
When a untranslated error message pass through the translation pecan hook, the previous translated error is send to the client. This patch fix that by reseting the "translatable_error" of the translation pecan hook before each request. Change-Id: Icee79cf09fd696655048c7c0cf8a3d6706e31701 Fixes: bug #1260398
This commit is contained in:
parent
4acf9ed388
commit
02d017022b
@ -74,6 +74,9 @@ class TranslationHook(hooks.PecanHook):
|
|||||||
self.local_error = threading.local()
|
self.local_error = threading.local()
|
||||||
self.local_error.translatable_error = None
|
self.local_error.translatable_error = None
|
||||||
|
|
||||||
|
def before(self, state):
|
||||||
|
self.local_error.translatable_error = None
|
||||||
|
|
||||||
def after(self, state):
|
def after(self, state):
|
||||||
if hasattr(state.response, 'translatable_error'):
|
if hasattr(state.response, 'translatable_error'):
|
||||||
self.local_error.translatable_error = (
|
self.local_error.translatable_error = (
|
||||||
|
@ -18,9 +18,11 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
"""Test basic ceilometer-api app
|
"""Test basic ceilometer-api app
|
||||||
"""
|
"""
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import wsme
|
||||||
|
|
||||||
from ceilometer.api import acl
|
from ceilometer.api import acl
|
||||||
from ceilometer.api import app
|
from ceilometer.api import app
|
||||||
@ -207,3 +209,19 @@ class TestApiMiddleware(FunctionalTest):
|
|||||||
fault = response.xml.findall('./error/faultstring')
|
fault = response.xml.findall('./error/faultstring')
|
||||||
for fault_string in fault:
|
for fault_string in fault:
|
||||||
self.assertEqual(fault_string.text, self.en_US_translated_error)
|
self.assertEqual(fault_string.text, self.en_US_translated_error)
|
||||||
|
|
||||||
|
def test_translated_then_untranslated_error(self):
|
||||||
|
resp = self.get_json('/alarms/alarm-id-3', expect_errors=True)
|
||||||
|
self.assertEqual(resp.status_code, 404)
|
||||||
|
self.assertEqual(json.loads(resp.body)['error_message']
|
||||||
|
['faultstring'], "Alarm alarm-id-3 Not Found")
|
||||||
|
|
||||||
|
with mock.patch('ceilometer.api.controllers.v2.EntityNotFound') \
|
||||||
|
as CustomErrorClass:
|
||||||
|
CustomErrorClass.return_value = wsme.exc.ClientSideError(
|
||||||
|
"untranslated_error", status_code=404)
|
||||||
|
resp = self.get_json('/alarms/alarm-id-5', expect_errors=True)
|
||||||
|
|
||||||
|
self.assertEqual(resp.status_code, 404)
|
||||||
|
self.assertEqual(json.loads(resp.body)['error_message']
|
||||||
|
['faultstring'], "untranslated_error")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user