1

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)

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 Answers1

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