twisted/klein — pull request #26 by russellhaering (2013-10-03 22:26:47+00:00)
Title: Support user-defined error handlers

This change fixes #24 by allowing users to define a chain of error handlers. Handlers can be used in two ways, shown below:

```python
class MyAwesomeThing(object):
app = Klein()

@app.route('/{userid}')
def users_stuff(self, request, userid):
pass

@app.handle_errors(SpecificError)
def handle_specific_error(self, request, failure):
pass

@app.handle_errors
def my_error_handler(self, request, failure):
pass
```

Users can register a handler for a specific class (or classes) of Exception, or use the basic syntax for a catch-all. Error handlers end up getting chained together with calls to `Failure.check()` to scope handlers to the appropriate Exception types.

In a separate PR I intend to cause HTTPExceptions raised during request routing to be passed to the same handler chain, which would allow users to, for example, define custom 404 handlers.