Add error code to handled exceptions

When an exception is handled, it returns a 200 code by default. Unless I'm misunderstanding, this creates problems in RESTful systems that are looking out for the HTTP status code.

This patch defaults any exceptions to a 500 error. If the exception has a code, then that code is used.

I would add a test for this but the tests fail in my local workspace, please see: https://gist.github.com/gavD/29414329823551fee616