在开发/生产模式下处理Rails中的异常

时间:2012-05-17 08:32:07

标签: ruby-on-rails-3 exception-handling

为了处理异常,我决定使用Exception_notifier gem。这是我在/config/enviroments/development.rb

中使用的代码
  config.middleware.use ExceptionNotifier,
    :email_prefix => "[ERROR] ",
    :sender_address => '"dev-Notifier" <error@my_emails.com>',
    :exception_recipients => ['error@my_emails.com']

如果我语法失败,例如:

@article = Article.fixnd(params[:id])

我会收到有关它的错误电子邮件。

但是如果我将URL设置为此地址:

http://localhost:3001/articlesssssss

我会收到错误,但不会发送电子邮件。如果我设置为url坏地址(404错误),则会出现相同的行为。

我需要设置什么,如果我想收到有关应用中每个错误的电子邮件(也是关于上面的最后2个错误)?

这是我在ApplicationController中使用的部分:

  unless Rails.application.config.consider_all_requests_local
    rescue_from Exception, with: :render_500
    rescue_from ActionController::RoutingError, with: :render_404
    rescue_from ActionController::UnknownController, with: :render_404
    rescue_from ActionController::UnknownAction, with: :render_404
    rescue_from ActiveRecord::RecordNotFound, with: :render_404
  end

1 个答案:

答案 0 :(得分:0)

在Exception_notification文档中有一个答案:

https://github.com/smartinez87/exception_notification/#rack-x-cascade-header

  

Rack X-Cascade Header

     

某些机架应用程序(特别是Rails)使用“X-Cascade”标头   将请求处理职责传递给下一个中间件   叠加。

     

Rails的路由中间件使用这种策略,而不是提高   例外,处理路由错误(例如404s);被通知   每当发生404时,将此选项设置为“false”。

     

:ignore_cascade_pass

     

布尔值,默认值:true

     

设置为false以在另一个机架中间件时触发通知   将“X-Cascade”标题设置为“传递”。

相关问题