perwendel/spark — pull request #131 by thebigb (2014-03-23 00:22:09+00:00)
Title: Exception mapper

This pull request implements a simple exception mapper that allows you to handle exceptions of a configured type for all routes and filters.

Example:
```
get(new Route("/throwexception") {
@Override
public Object handle(Request request, Response response) {
throw new UnsupportedOperationException();
}
});

exception(new ExceptionHandler(UnsupportedOperationException.class) {
@Override
public void handle(Exception exception, Request request, Response response) {
response.body("Exception handled");
}
});
```

For the `ExceptionMapper` I went with a singleton, because I couldn't figure out another way to hook it in somewhat cleanly.

I've also hacked in [`getDelegate()`](#diff-5635973fffab3b544b83a8a7ede67506) to be able to fetch the body, which the `ExceptionHandler` can set using `response.body("Something")`. This is probably not the best solution, but it's the best I could figure out.

I'll gladly process any feedback.