diff --git a/aodh/api/hooks.py b/aodh/api/hooks.py index a5746ad2..62cfc2d4 100644 --- a/aodh/api/hooks.py +++ b/aodh/api/hooks.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import threading - from oslo_policy import policy from pecan import hooks @@ -45,17 +43,11 @@ class DBHook(hooks.PecanHook): class TranslationHook(hooks.PecanHook): - def __init__(self): - # Use thread local storage to make this thread safe in situations - # where one pecan instance is being used to serve multiple request - # threads. - self.local_error = threading.local() - self.local_error.translatable_error = None - - def before(self, state): - self.local_error.translatable_error = None - def after(self, state): + # After a request has been done, we need to see if + # ClientSideError has added an error onto the response. + # If it has we need to get it info the thread-safe WSGI + # environ to be used by the ParsableErrorMiddleware. if hasattr(state.response, 'translatable_error'): - self.local_error.translatable_error = ( + state.request.environ['translatable_error'] = ( state.response.translatable_error) diff --git a/aodh/api/middleware.py b/aodh/api/middleware.py index a7e098aa..dd67d69a 100644 --- a/aodh/api/middleware.py +++ b/aodh/api/middleware.py @@ -26,7 +26,6 @@ from oslo_log import log import six import webob -from aodh.api import hooks from aodh import i18n from aodh.i18n import _ @@ -82,13 +81,7 @@ class ParsableErrorMiddleware(object): app_iter = self.app(environ, replacement_start_response) if (state['status_code'] // 100) not in (2, 3): req = webob.Request(environ) - # Find the first TranslationHook in the array of hooks and use the - # translatable_error object from it - error = None - for hook in self.app.hooks: - if isinstance(hook, hooks.TranslationHook): - error = hook.local_error.translatable_error - break + error = environ.get('translatable_error') user_locale = self.best_match_language(req.accept_language) if (req.accept.best_match(['application/json', 'application/xml']) == 'application/xml'):