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
Post a Comment