[openstack-dev] [wsme] WSME/Pecan serializing Exceptions

Doug Hellmann doug.hellmann at dreamhost.com
Tue Feb 4 15:53:03 UTC 2014


On Tue, Feb 4, 2014 at 9:43 AM, Sylvain Bauza <sylvain.bauza at gmail.com>wrote:

> Hi,
>
> The WSME wsexpose() decorator for Pecan serializes any Exception being
> raised on a controller [1]
>
> I can understand the behaviour for security and visualization concerns,
> but I was wondering if it was possible to add an extra parameter to the
> decorator in order to explicitely raise the Exception ?
>
> My concern is that it would be far easier to implement either a Pecan hook
> or an middleware app that would then capture the Exception and return it on
> a templatized way.
>
> At the moment, I have to play with raw strings for trying to deduce which
> exception it was and correctly set the return values...
>
> What do you think of it, people ? Would it be worth patching it ?
>

If the exception has a "code" attribute, it is set as the status code for
the response. Otherwise, the status is set to 500 as a default. There are
a set of exception classes in wsme.exc that set the status code and can be
used as base classes for exceptions in the API controllers.

The typical way to handle this is to catch underlying exceptions for
situations that are known to be likely (no such object, permission issue,
etc.) and re-raise an exception with a valid status code and useful
message. Unexpected exceptions then result in a 500.

Doug



>
> -Sylvain
>
> [1] https://github.com/stackforge/wsme/blob/master/wsmeext/pecan.py#L90
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20140204/0ef5b5ab/attachment.html>


More information about the OpenStack-dev mailing list