I’m creating rails–powered app, which acts as JSON API, and is hosted on heroku.
Right now, if exception is raised, heroku returns me proper http response code, and customisable HTML page as response. However, since I’m not using HTML format, and even if I set Accept: application/json
header that HTML response is returned – which is incorrect for me. Is it possible to customise response, and return some kind of JSON? (If not, response without body will be also fine)
Asked
Active
Viewed 1,318 times
1

user1105595
- 591
- 2
- 8
- 20
-
did you ever have any luck with this? heroku has the ability for you to define the error pages, curious if you could just load a json text file as the error page ... – Ralph Callaway Jun 02 '16 at 17:33
1 Answers
1
You should catch exceptions in the controller, and head :not_found
or something similar.
http://guides.rubyonrails.org/action_controller_overview.html#rescue_from
http://rails.rubyonrails.org/classes/ActionController/Base.html#M000466

rewritten
- 16,280
- 2
- 47
- 50
-
of course I can, but I can’t catch easly all errors with that approach – user1105595 Oct 03 '12 at 14:01
-
why can't you? you could rescue_from Exception and handle them all. Check out http://stackoverflow.com/a/6773038/363881 for an example. – Jesse Wolgamott Oct 03 '12 at 14:13
-
Well… I can’t catch routing error easly (ie. without messing my routes with wildcard route) – user1105595 Oct 04 '12 at 07:11