简体   繁体   中英

Customize exception_notifier, Ruby on Rails

I have successfully added the exception_notifier to my rails app, and it is emailing a notification for all exceptions at the application level (which is exactly what I want). The only problem is that I need to have a few short lines of code ran whenever an exception is raised as well, and am certain that there is a way to add these lines of code onto the notifier. But despite reading the documentation found here: https://github.com/smartinez87/exception_notification I am still unclear what/where I should put things. Can someone please explain this a bit better for me. I am relatively new to ROR. I just need to add some additional code to run whenever the notifier is alerted to an exception.

This seems to be the correct link to the background notification: Using a begin rescue should do the trick.

def method
  sentence1
  begin
    sentence2
    sentence3
  rescue => e
    ExceptionNotifier.notify_exception(e)
    Sentence code1
    return action
  end
end

As explained here:

https://github.com/smartinez87/exception_notification#background-notifications

So as a shorthand: To do code before or after the notification is sended, but outside of the notification method you need to catch the exception in the method who raised it and work there.

But remember: Catching exceptions should be an exception. If you know what could go wrong, try to fix it, not to catch it.

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