尝试覆盖
ActionController::Failsafe
,或者在堆栈上粘贴另一个中间件,您应该能够从那里捕获几乎所有的异常,并且可以随意捕获302。
例子:
class DbFailsafe
def new(app)
@app = app
end
def call(env)
@app.call(env)
rescue DataBaseError => e
[302, {"Content-Type" => "text/plain", "Location" => "http://otherserver.com/sorrt-the-site-is-down.html"}, ["You are being redirected to http://otherserver.com/sorrt-the-site-is-down.html"]]
end
end
在您的环境中
config.middleware.insert_after ::ActionController::Failsafe, DbFailsafe
我建议(因为我们应该使用5xx而不是3xx)使用js重定向呈现简单页面。这很简单,只需编辑即可
public/500.html
.