我有一個在tomcat下運行的jruby rails應用程序。 url中的一些格式不正確的查詢字符串會導致Rack在生產模式下顯示異常堆棧跟蹤。有沒有辦法妥善處理。我不認爲我可以使用config.exception_app,因爲它只會處理從rails應用程序生成的異常。在這種情況下,異常在到達rails應用程序之前生成。這裏是個例外:如何在到達您的導軌應用程序之前處理從機架產生的異常
org.jruby.exceptions.RaiseException: (ArgumentError) invalid %-encoding (/"{}\%#$())
at Module.decode_www_form_component(jar:file:/usr/local/apache-
tomcat/webapps/ROOT/WEB-INF/lib/gems-gems-jruby-jars-1.7.3-lib-jruby-stdlib-
1.7.3.jar!/META-INF/jruby.home/lib/ruby/1.9/uri/common.rb:898)
at Rack::Utils.unescape(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-1.4.5/lib/rack/utils.rb:41)
at Rack::Utils.parse_nested_query(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-1.4.5/lib/rack/utils.rb:94)
at org.jruby.RubyArray.map(org/jruby/RubyArray.java:2361)
at Rack::Utils.parse_nested_query(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-1.4.5/lib/rack/utils.rb:94)
at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1613)
at Rack::Utils.parse_nested_query(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-1.4.5/lib/rack/utils.rb:93)
at Rack::Request.parse_query(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-1.4.5/lib/rack/request.rb:332)
at Rack::Request.POST(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-1.4.5/lib/rack/request.rb:209)
at Rack::MethodOverride.method_override(/usr/local/apache-
tomcat/webapps/ROOT/WEB-INF/gems/gems/rack-1.4.5/lib/rack/methodoverride.rb:26)
at Rack::MethodOverride.call(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-1.4.5/lib/rack/methodoverride.rb:14)
at Rack::Runtime.call(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-1.4.5/lib/rack/runtime.rb:17)
at ActiveSupport::Cache::Strategy::LocalCache::Middleware.call(/usr/local/apache-
tomcat/webapps/ROOT/WEB-INF/gems/gems/activesupport-
3.2.13/lib/active_support/cache/strategy/local_cache.rb:72)
at Rack::Lock.call(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-1.4.5/lib/rack/lock.rb:15)
at Rack::Cache::Context.forward(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-cache-1.2/lib/rack/cache/context.rb:136)
at Rack::Cache::Context.pass(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-cache-1.2/lib/rack/cache/context.rb:143)
at Rack::Cache::Context.invalidate(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-cache-1.2/lib/rack/cache/context.rb:155)
at Rack::Cache::Context.call!(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-cache-1.2/lib/rack/cache/context.rb:71)
at Rack::Cache::Context.call(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/rack-cache-1.2/lib/rack/cache/context.rb:51)
at Rails::Engine.call(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/railties-3.2.13/lib/rails/engine.rb:479)
at Rails::Application.call(/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/gems/gems/railties-3.2.13/lib/rails/application.rb:223)
at Rack::Handler::Servlet.call(file:/usr/local/apache-tomcat/webapps/ROOT/WEB-
INF/lib/gems-gems-jruby-rack-1.1.13.1-lib-jruby-rack-
1.1.13.1.jar!/rack/handler/servlet.rb:22)
java land默認是在你的應用服務器上配置一個500模板,也就是你的tomcat – phoet
我最終寫了一個機架中間件來攔截異常並處理它。 – DrChanimal