From 6b13ee0c3b446b7fc4f440dd58c9226bf4abfdf8 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Thu, 13 Feb 2014 02:51:45 +0900 Subject: [PATCH] Avoid using "raise" to reraise with modified exception The code changes the exception and reraises it. This commit changes the code to use the same way as excutils.save_and_reraise_exception does to ensure the exception context. This is the last patch of reraise clean up series. Closes-Bug: #1279813 Change-Id: I8787dcbdc8321f75964de26e97cae395707aafc2 --- neutron/api/v2/resource.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/neutron/api/v2/resource.py b/neutron/api/v2/resource.py index fb139b2ac..59f4dc550 100644 --- a/neutron/api/v2/resource.py +++ b/neutron/api/v2/resource.py @@ -17,7 +17,10 @@ Utility methods for working with WSGI servers redux """ +import sys + import netaddr +import six import webob.dec import webob.exc @@ -103,11 +106,12 @@ def Resource(controller, faults=None, deserializers=None, serializers=None): kwargs = {'body': body, 'content_type': content_type} raise mapped_exc(**kwargs) except webob.exc.HTTPException as e: + type_, value, tb = sys.exc_info() LOG.exception(_('%s failed'), action) translate(e, language) - e.body = serializer.serialize({'NeutronError': e}) - e.content_type = content_type - raise + value.body = serializer.serialize({'NeutronError': e}) + value.content_type = content_type + six.reraise(type_, value, tb) except NotImplementedError as e: e = translate(e, language) # NOTE(armando-migliaccio): from a client standpoint -- 2.45.2