Better JSON error-catching

The JSON plugin will now catch all exceptions, so that the JavaScript client can always know what the source of an error is. If `debug` mode is set, the traceback will also be included in the error.