Pecan's on_error() hook never gets trigged when used with WSME

Bug #1256042 reported by Lucas Alvares Gomes
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
WSME
Confirmed
High
Jianing Yang

Bug Description

The WSME wsexpose decorator capture all the exceptions serialize then and return as a response[1], and so the on_error() hook of pecan that is dedicated for unhandled exceptions never will get trigged.

[1] https://github.com/stackforge/wsme/blob/master/wsmeext/pecan.py#L70-L102

Revision history for this message
Jianing Yang (jianingy) wrote :

WSME should provide a way to let user handle exceptions instead of catching them all.

Changed in wsme:
status: New → Confirmed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to wsme (master)

Fix proposed to branch: master
Review: https://review.openstack.org/64551

Jianing Yang (jianingy)
Changed in wsme:
assignee: nobody → Jianing YANG (jianingy)
Revision history for this message
Christophe de Vienne (cdevienne) wrote :

Reproducing the comment I did on the abandoned patch, because it describes how I would solve this.

"""
Well, we can already override some things by redefining wsme.api.format_exception.

It can definitely be improved to be more accessible, allowing the application to provide an exception handler that will decide what kind of exception we have.

I do not think it is necessary to move entirely in the middleware, nor a good idea, because in the adapter we still have an easy access to the function definition,

So here is how I would do :

    Define a function signature for an exception handler. Something like handler(funcdef, exception_infos). The behavior of this handler is to :

* return a data struture to be sent back (as format_exception does), along with a specific error code if needed,
* raise an exception that will not be caught by the adapter

    Provide an api to set a handler as the default exception handler (wsme.api.set_default_error_handler).

    Add a new parameter to the generic expose that can set a specific error handler on a funcdef

    Modify the adapters to use the error handler defined on the funcdef, and if not defined the default one.

With this approach, doing what you want (let the middleware handle the exceptions) would be doable by setting a default exception handler that only reraise them.

It could also be done by making the default exception handler using options set on the funcdef to selectively reraise the client or server errors.
"""

Revision history for this message
Haomeng,Wang (whaom) wrote :

@Jianing, any update for this defect? Our Ironic need this patch, thanks.

Changed in wsme:
importance: Undecided → High
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.