Improve json_handler decorator

It will now sanely respond with a 405 error if the method is not POST or
a 400 error if the input is invalid. A wrapped function can now indicate
by raising a certain exception that a status code other than 200 or 500
should be returned.