我使用的是Rails3.2、mongoid3、devise 2.2.4、passenger和nginx。
当我的rails应用程序找不到MongoDB时,我收到错误消息“我们很抱歉,但有些地方出了问题”。我希望将错误消息更改为与错误更相关的内容。例如:无法连接到数据库。
我看到,Moped::Errors::ConnectionFailure被抛出,但我不能用rescue_from在应用程序控制器中挽救它。当devise试图在初始化时从会话中获取用户时,似乎出现了错误。离开:authenticate_user!帮不上忙。
发布于 2014-10-22 02:00:33
找到发生错误的行。使用begin; rescue块将其包围,如下所示:
begin # code which raises the error rescue Moped::Errors::ConnectionFailure => e raise MyOwnError end
当然,您需要定义MyOwnError:
class MyOwnError < StandardError; end
祝好运。您可以尝试Googling一下Ruby错误和异常。
https://stackoverflow.com/questions/26281510
复制相似问题