Custom Error Handling with Rails 4.0

后端 未结 5 722
我寻月下人不归
我寻月下人不归 2020-12-24 14:49

I\'m building a Ruby on Rails api using Ruby 2.0 and Rails 4.0. My app is almost solely a JSON API, so if an error occurs (500, 404), I want to capture that error and return

5条回答
  •  轮回少年
    2020-12-24 15:22

    Try this if you want respond to all types of errors in the same way

    rescue_from StandardError, :with => :error_render_method

    If you don't want this behavior in your development mode, add the above code under

    unless Rails.application.config.consider_all_requests_local

提交回复
热议问题