Ruby on rails 如何在Rails中捕获整个应用程序的ArgumentError? 环境 轨道3.1 Ruby 1.9.1
我已经尝试了Ruby on rails 如何在Rails中捕获整个应用程序的ArgumentError? 环境 轨道3.1 Ruby 1.9.1,ruby-on-rails,ruby,exception,Ruby On Rails,Ruby,Exception,我已经尝试了应用程序\u控制器,但似乎不起作用 我可能做错了什么 rescue_from ArgumentError do |exception| flash.now[:error] = "Arguments for your request are incorrect" #ExceptionNotifier::Notifier.background_exception_notification(exception).deliver if Rails.env.produc
应用程序\u控制器
,但似乎不起作用
我可能做错了什么
rescue_from ArgumentError do |exception|
flash.now[:error] = "Arguments for your request are incorrect"
#ExceptionNotifier::Notifier.background_exception_notification(exception).deliver if Rails.env.production?
redirect_to root_url, :alert => exception.message
end
我试图处理的例外情况
A ArgumentError occurred in marketplace#index:
invalid byte sequence in UTF-8
.bundle/gems/ruby/1.9.1/gems/rack-1.4.5/lib/rack/utils.rb:104:in `normalize_params'
或
如果有人还在寻找答案,我会参考这个答案 在下的
应用程序\u controller.rb
rescue\u from ActionController::RoutingError,带:->{render\u 404}
加
rescue\u from ArgumentError,with:->{render\u 404}
这将捕获你所有的
论证错误
请在你提出论证错误的地方发布。如果这是你的提出的ing。你问题中的两个错误似乎来自rack中间件。它们在到达rails应用程序之前出现在堆栈中,因此您的应用程序控制器永远不会知道这些异常。检查一下这个,也许这只手表,这只火车头-
A ArgumentError occurred in connect#index:
invalid %-encoding (%u2713)
.bundle/gems/ruby/1.9.1/gems/rack-1.4.5/lib/rack/backports/uri/common_192.rb:46:in `decode_www_form_component'