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:
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.
Error handlers would need a reference to the wsgi app. This would be convenient so as to access other methods like
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): self.error_handlers.append( handler.__get__(self) ) return handler # ... app = TrytonWSGI() # ... @app.add_error_handler def _(self, request, e): # .... return self.make_response(request, some_data)
Does this make sense to you?