3

我们的 Rails 应用程序有时会收到一个完全乱码的 URL,这会导致 Rack 升高URI::InvalidURIError。我们的异常通知系统 (HoneyBadger) 然后会收到此错误的通知。

但是,我不想知道这些错误:我希望 Rack 只记录它们(如果可能的话)并吞下它们。

该应用程序ActionController::RoutingError通过以下方式处理routes.rb

# Default route, because these would normally not go through the application rescue_from block
match('*path', to: 'application#routing_error') unless Rails.env.development?

...然后在.中发生路由错误时记录(但不通知)ApplicationController#routing_error

但是,这个无效的 URI 错误发生在路由看到 URL 之前。

这是导致问题的示例 URL(当然,域名已更改)- http://www.whatever.com/HD2EU]. 以及随之而来的堆栈跟踪:

[PROJECT_ROOT]/vendor/ruby-1.9.3/lib/ruby/1.9.1/uri/common.rb:176:in `split`
[PROJECT_ROOT]/vendor/ruby-1.9.3/lib/ruby/1.9.1/uri/common.rb:211:in `parse`
[PROJECT_ROOT]/vendor/ruby-1.9.3/lib/ruby/1.9.1/uri/common.rb:747:in `parse`
[PROJECT_ROOT]/vendor/ruby-1.9.3/lib/ruby/1.9.1/uri/common.rb:994:in `URI`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/rack-ssl-1.3.3/lib/rack/ssl.rb:50:in `redirect_to_https`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/rack-ssl-1.3.3/lib/rack/ssl.rb:32:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:479:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:223:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:552:in `process_client`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:632:in `worker_loop`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.5.130/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.5.130/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `block (4 levels) in <top (required)>`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:500:in `spawn_missing_workers`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:142:in `start`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.3/bin/unicorn:126:in `<top (required)>`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/bin/unicorn:23:in `load`
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/bin/unicorn:23:in `<main>`
4

1 回答 1

1

我只是简单地将其添加到 honeybadger.rb 初始化程序中:

config.ignore << URI::InvalidURIError

于 2014-05-08T18:43:23.273 回答