Improve wsgi error handlers feature

The WSGI Tryton application already has an undocumented error_handlers feature:

Right now, error handlers are passed a handled exception and are expected to return a response object. Yet, in order to be useful as error pages like many web frameworks have it would need some improvements:

  1. Error handlers should be passed the request as parameter. This is necessary to localize the response, include some context such as the user or any request inspected information, answer in a proper content-type customized views (i.e. json/xml for rpc or user application calls, html with custom css for web browsers visiting pages like /dbname/ir/html/** or anything a particular deployment might need). And very important, to be able to copy the id paramter for RPC calls, otherwise the Tryton GTK client rejects any response.

  2. Error handlers would need a reference to the wsgi app. This would be convenient so as to access other methods like make_response.

I imagine the wsgi implementing a decorator to register error handlers like

class TrytondWSGI(object):

    def __init__(self):
        # ...
        self.error_handlers = []

    def add_error_handler(self, handler):
        return handler

    # ...

app = TrytonWSGI()

# ...

def _(self, request, e):
    # ....
    return self.make_response(request, some_data)

Does this make sense to you?

1 Like

That’s make sense to me. Could you submit the change?

I’ll be glad to. I should create an issue, shouldn’t I? Issue 8548: Improve wsgi error handlers feature - Tryton issue tracker

Yes, and then you should submit your proposal

1 Like