ruby on rails - rescue_from not working with ActionController::BadRequest -


using Rail 4, I'll work with rescue_from with ActionController :: BadRequest can not be found for :

application_controller.rb

  rescue_from ActionController :: BadRequest, with: raise_bad_request def raise_bad_request (Nothing present: true, position: 404) end    

inside the controller You have to rescue_from to collect errors only (in action, views or filters) inside your controller.

It looks like Passes the ActionController :: BadRequest route (middleware stack before requesting to do the controller somewhere).

If you write your middle class this way, then you can take action on such errors:

  class HandleErrorsMiddleware def initialize (app) @app = app End DIF Call (env) @ app call (env) Rescue control: BadRequest ApplicationController.action (raise_bad_request) .call (env) End End   

raise_bad_request ApplicationController

You must add this middleware to config / application.rb

  config.middleware .insert_before 'ActionDispatch :: ParamsParser', 'HandleErrorsMiddleware'    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -