I have a Rails app that includes a JSON API interface. When values are properly specified, the controller handles the happy path just fine and JSON is rendered as output.
However, if there's a problem with the input, an exception is raised and some templates in rescues
are rendered instead. I'd really just like to return a JSON error along the lines of { "error": { "msg": "bad request", "params": ... } }
and the appropriate HTTP status code (e.g. 403 if they weren't authenticated). But I only want this to be applicable to requests against anything in example.com/api/...
.
How can I do that?