404、500 的自定义错误页面,但默认的 500 错误消息来自哪里?

编程入门 行业动态 更新时间:2024-10-23 16:23:09
本文介绍了404、500 的自定义错误页面,但默认的 500 错误消息来自哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

目前正在制作中,我收到了以下文字:

Currently in production I'm getting this text:

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.

该页面上没有任何 HTML.此代码位于何处?我没有 public/500.html 文件.

There isn't any HTML on that page. Where is this code situated? I don't have a public/500.html file.

在我的路线中,我有:

get "/404", :to => "errors#error_404" get "/422", :to => "errors#error_404" get "/500", :to => "errors#error_500" get "/505", :to => "errors#error_505"

错误控制器:

class ErrorsController < ApplicationController def sub_layout "left" end def error_404 render :status => 404, :formats => [:html], :layout => "white", :sub_layout => "left" end def error_422 render :status => 422, :formats => [:html], :layout => "white", :sub_layout => "left" end def error_500 render :status => 500, :formats => [:html], :layout => "white", :sub_layout => "left" end def error_505 render :status => 505, :formats => [:html], :layout => "white", :sub_layout => "left" end end

如何让它始终加载我的自定义错误?对于某些错误,它只会抛出来自 Ruby on Rails 核心某处的这两行文本.我希望它每次都能提取我自定义样式的错误页面!

How do I make it load my custom errors always? On some errors, it just throws those two lines of text coming somewhere from the Ruby on Rails core. I want it to pickup my custom styled error pages every time!

推荐答案

您遇到的错误正在被抛出

The error you are experiencing is being thrown from

github/rails/rails/blob/4-0-stable/actionpack/lib/action_dispatch/middleware/show_exceptions.rb#L18-L22

这意味着您的异常被拯救的代码本身就是抛出异常.您可以检查日志中的文本:

This means the code your exceptions are getting rescued by are themselves throwing exceptions. You can check your logs for text:

故障安全响应时出错:

确定异常的真正原因,从而解决您的问题.

to identify what the exceptions really are originating from and thus solve your problem.

更多推荐

404、500 的自定义错误页面,但默认的 500 错误消息来自哪里?

本文发布于:2023-10-31 15:43:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546538.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   自定义   来自哪里   消息   页面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!