ruby-on-rails – ExceptionNotifier和rescue_from
发布时间:2020-12-16 22:09:58 所属栏目:百科 来源:网络整理
导读:我试图实现exception_notifier和一个自定义的异常处理 在我的rails 3应用程序当我只使用异常通知器一切正常. 在开发模式中 config.consider_all_requests_local = false 和一个rescue_from在我的application_controller中: unless Rails.application.config
我试图实现exception_notifier和一个自定义的异常处理
在我的rails 3应用程序当我只使用异常通知器一切正常. 在开发模式中 config.consider_all_requests_local = false 和一个rescue_from在我的application_controller中: unless Rails.application.config.consider_all_requests_local rescue_from Exception,:with => :render_error end def render_error(exception) ExceptionNotifier::Notifier.exception_notification(request.env,exception).deliver end 在我的application.rb config.middleware.use ExceptionNotifier,:email_prefix => "Error: ",:sender_address => %{"notifier" <notifier@wannagohome.com>},:exception_recipients => %w{ myself@fail.com } 唯一的问题似乎是,这些选项没有加载到request.env中. 解决方法
exception_notification是Rails 3中的中间件,所以这些选项直接设置在处理调用的类中,该类不会在环境中设置它们,除非它捕获异常(
see here).
This fork添加了一个可以使用的background_exception_notification方法.我借了这个想法,刚刚添加了这个帮助方法:
def background_exception_notification(env,exception) if notifier = Rails.application.config.middleware.detect { |x| x.klass == ExceptionNotifier } env['exception_notifier.options'] = notifier.args.first || {} ExceptionNotifier::Notifier.exception_notification(env,exception).deliver env['exception_notifier.delivered'] = true end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |