Avoid serializing CinderExceptions before they are translated

CinderExceptions were being unicode()'d when being wrapped in an
HTTPException, and this was causing the delayed translation to fail for
those errors.

Also, CinderExceptions have a 'message' class attribute that holds the
generic error message template, e.g. "Backup  %(backup_id)s is not
found", unfortunately, because the names are the same, it was
overshadowing the actual exception instance 'message', e.g. "Backup 1 is
not found", when translating. This patch puts the exception's actual
message in a new field called 'msg'.

Fixes Bug: #1214102

Change-Id: Ied9abcc3d05454852c0a5891432eb181220a744e
This commit is contained in:
Luis A. Garcia
2013-08-19 20:19:57 +00:00
parent 5d6c11facc
commit 2bec15e185
11 changed files with 40 additions and 35 deletions

View File

@@ -183,7 +183,7 @@ class VolumeActionsController(wsgi.Controller):
try:
volume = self.volume_api.get(context, id)
except exception.VolumeNotFound as error:
raise webob.exc.HTTPNotFound(explanation=unicode(error))
raise webob.exc.HTTPNotFound(explanation=error.msg)
authorize(context, "upload_image")
image_metadata = {"container_format": params.get("container_format",
"bare"),
@@ -195,7 +195,7 @@ class VolumeActionsController(wsgi.Controller):
image_metadata,
force)
except exception.InvalidVolume as error:
raise webob.exc.HTTPBadRequest(explanation=unicode(error))
raise webob.exc.HTTPBadRequest(explanation=error.msg)
except ValueError as error:
raise webob.exc.HTTPBadRequest(explanation=unicode(error))
except rpc_common.RemoteError as error: