Rails ActionController :: BadRequest在生产服务器上导致500服务器错误 [英] Rails ActionController::BadRequest causes 500 Server Error on production server

查看:118
本文介绍了Rails ActionController :: BadRequest在生产服务器上导致500服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个土耳其语网站,一些搜索引擎抓取了一些旧链接.链接似乎格式错误或无法处理,因此导致ActionController::BadRequest错误.在具有development env的本地计算机上,这导致返回具有ActionController::BadRequest的Rails错误页面.

We have a Turkish website and some old links are crawled by some search engines. The links seem to be malformed or cannot be processed and therefore causing ActionController::BadRequest error. On the local machine with development env this causes to return the Rails error page with ActionController::BadRequest.

但是在服务器上,我们会得到一个500 server error.在其他几个页面上也对此问题进行了讨论,例如

But on the Server we get an 500 server error. This issues is discussed on several other pages like here. But none of the solutions helped.

在两种情况下,我们都希望重定向到page not found页.

In both cases we would like to redirect to a page not found-page.

由于前面提到的文章,我已经尝试在ApplicationController中使用rescue_from ActionController::BadRequestrescue_from ActionController::RoutingError,他们指出BadRequest变成了RoutingError.

I already tried to rescue_from ActionController::BadRequest and rescue_from ActionController::RoutingError in ApplicationController because of the aforementioned article, where they state that BadRequest turns into RoutingError.

但是他们俩都没有.

我希望有人遇到同样的问题并已经解决.预先感谢您的回答.

I hope someone had the same problem and already resolved it. Thanks in advance for your answers.

问题网址的一个示例是http://localhost:3000/Di%c5%ef%bf%bd-f%c4%b1r%c3%a7as%c4%b1.

One example problem-url is http://localhost:3000/Di%c5%ef%bf%bd-f%c4%b1r%c3%a7as%c4%b1.

端子输出:

ActionController::BadRequest (ActionController::BadRequest):
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:37:in `block in call'
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:33:in `each'
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:33:in `call'
  actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
  actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
  newrelic_rpm (3.6.4.122) lib/new_relic/rack/error_collector.rb:12:in `call'
  newrelic_rpm (3.6.4.122) lib/new_relic/rack/agent_hooks.rb:22:in `call'
  newrelic_rpm (3.6.4.122) lib/new_relic/rack/browser_monitoring.rb:16:in `call'
  newrelic_rpm (3.6.4.122) lib/new_relic/rack/developer_mode.rb:28:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__4278100521352222029__call__callbacks'
  activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  rollbar (0.11.7) lib/rollbar/middleware/rails/show_exceptions.rb:19:in `call_with_rollbar'
  actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
  railties (4.0.0) lib/rails/engine.rb:511:in `call'
  railties (4.0.0) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  puma (2.6.0) lib/puma/server.rb:486:in `handle_request'
  puma (2.6.0) lib/puma/server.rb:357:in `process_client'
  puma (2.6.0) lib/puma/server.rb:250:in `block in run'
  puma (2.6.0) lib/puma/thread_pool.rb:92:in `call'
  puma (2.6.0) lib/puma/thread_pool.rb:92:in `block in spawn_thread'

最诚挚的问候

推荐答案

我想您的路由或Rack中间件之一无效,并导致500错误.在新的Rails应用程序中,URL http://localhost:3000/Di%c5%ef%bf%bd-f%c4%b1r%c3%a7as%c4%b1没有错误行为-应用程序按预期返回404错误.还请求http://127.0.0.1:3000/?foo[]=array&foo[hash]=hash返回绝对正确的响应,并显示400错误(BadRequest).

I suppose that one of your routes or Rack middleware is invalid and causes the 500 error. In new Rails app there is no incorrect behaviour with url http://localhost:3000/Di%c5%ef%bf%bd-f%c4%b1r%c3%a7as%c4%b1 - app returns a 404 error as expected. Also request to http://127.0.0.1:3000/?foo[]=array&foo[hash]=hash return absolutely correct response with 400 error (BadRequest).

尝试像这样重写路由:

Rails.application.routes.draw do
  get '/*path', :to => lambda { |env| [200, {}, [env.to_s]]}
  # omited
end

并查看响应状态-如果是200,则是Rails应用程序中的问题,否则是机架中间件中的其他任何地方.

and take a look to response status - if it 200, than problem in your Rails application, otherwise anywhere else in the rack middleware.

rails -v #=> Rails 4.1.1

这篇关于Rails ActionController :: BadRequest在生产服务器上导致500服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆