gpt4 book ai didi

ruby-on-rails - 在 Rails 环境中由 Rack 引发时如何拯救 URI::InvalidURIError?

转载 作者:行者123 更新时间:2023-12-04 18:08:49 27 4
gpt4 key购买 nike

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

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

应用在 routes.rb 中处理 ActionController::RoutingError:

# 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>`

最佳答案

我只是将它添加到 honeybadger.rb 初始值设定项中:

config.ignore << URI::InvalidURIError

关于ruby-on-rails - 在 Rails 环境中由 Rack 引发时如何拯救 URI::InvalidURIError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19713529/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com