简体   繁体   中英

ActionController::Metal How to catch all exceptions to send notification email?

I am using ActionController::Metal inherted controllers for for rails services, I want to catch all exceptions , So that I can notify myself through email

rescue_from Exception is not working

I have used above code in another app in application controller it is working good But not in this case

Which module should be included in to base controller in order to use it any help?

Code:

  rescue_from Exception do |exception|
    Rails.logger.warn "\n-EXCEPTION OCCURE IN APPLICATION-\n============\n-On\n-#{Time.now}\n======\nRequest-refer\n#{request.referer}\n=====\nrequest.xhr?\n#{request.xhr?}\n=======\nRequest environment\n#{request.env["HTTP_USER_AGENT"]}\n====\n-MESSAGE\n-#{exception.message}\n======\n-Url\n-#{request.url} \n============\n-Backtrace\n-#{exception.backtrace}"
  end

我不确定这是否能解决您的确切问题,或者您是否真的需要自己创建此问题,但是如果您愿意接受其他依赖项,则可以使用exception_notifier gem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM