Ensure json requests get json error response on failure

Normally rails sends an html page which can't be parsed by the client.