]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Avoid using "raise" to reraise with modified exception
authorAkihiro Motoki <motoki@da.jp.nec.com>
Wed, 12 Feb 2014 17:51:45 +0000 (02:51 +0900)
committerThomas Goirand <thomas@goirand.fr>
Thu, 13 Mar 2014 07:20:39 +0000 (15:20 +0800)
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

index fb139b2ac5a4b96fbe168c400f0325af67b9164a..59f4dc5501353c5dcd0338f4688192308c2fb782 100644 (file)
 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