【问题标题】:How to handle "NetworkError: 400 Bad Request" in rails?如何在 Rails 中处理“NetworkError:400 Bad Request”?
【发布时间】:2015-03-16 05:43:55
【问题描述】:

当用户在 url 本身中输入搜索字符串为 '%' 时,我遇到了错误。输入我的网址后看起来像

 http://localhost:3000/search/%

现在它显示“NetworkError: 400 Bad Request - http://localhost:3000/search/%”。我想重定向到其他页面并在发生错误时显示错误的请求图像。请给我一些建议。

我附上了错误图片。

更新

我已经尝试了以下。

config/application.rb:

 config.exceptions_app = self.routes

config/routes.rb:

match "/400", :to => "errors#bad_request"

它没有进入 bad_request 方法。

在日志中我收到错误

 Invalid request: Invalid HTTP format, parsing fails.

【问题讨论】:

    标签: ruby-on-rails ruby http routes bad-request


    【解决方案1】:

    您是否检查过这个gem 'utf8-cleaner',它会从环境中删除无效的UTF-8 字符,这样您的应用就不会卡住它们。

    如果您想要自定义错误页面:然后查看 this answer

    【讨论】:

    • 两者都不起作用。首先,控制并没有到达路线本身。我想问题出在薄
    猜你喜欢
    • 2015-09-21
    • 2017-05-08
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 2011-08-31
    • 1970-01-01
    相关资源
    最近更新 更多