【发布时间】:2019-11-14 08:31:43
【问题描述】:
我们正在从 Rails 4 升级到 Rails 5.2,我们的自定义错误页面开始出现故障。到目前为止,这只发生在我们的 QA 服务器上。如果我将开发环境设置为显示错误页面,它们就可以正常工作。
日志显示:
Processing by ErrorsController#not_found as HTML
Parameters: {"path"=>"does_not_exist"}
Rendering errors/not_found.html.haml
Rendered errors/not_found.html.haml (3.4ms)
Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.0ms)
页面响应是一个普通的、没有样式的通用消息:
500 Internal Server Error
If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong.
ErrorsController中的相关方法是:
class ErrorsController < ApplicationController
def not_found
error_tracking("404")
fix_request_format
respond_to do |format|
format.html { render template: 'errors/not_found', :layout => false, status: 404 }
format.all { render nothing: true, status: 404 }
end
end
模板渲染后出现 500 错误的原因是什么?
【问题讨论】:
-
日志文件中的实际错误是什么? 500 代码太笼统,无法帮助解决此问题
-
恐怕就是这样。这就是为什么我在这里。 ://
-
您可以访问任何日志文件吗?
-
@AFaderDarkly 你确定通常会有一个堆栈跟踪解释错误。
-
是的,遗憾的是在这种情况下没有堆栈跟踪。接下来我将尝试的事情包括检查系统日志(以防万一),删除 Airbrake(在 500 错误之后在日志中写入唯一的内容)并最终使用不同的技术来处理自定义错误(可能是一个关注类型对象混合到应用程序控制器。)这很可惜,因为我喜欢控制器类的简洁性。
标签: ruby-on-rails error-handling ruby-on-rails-5