Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1.67 KB

File metadata and controls

42 lines (33 loc) · 1.67 KB

Custom notifier

Simply put, notifiers are objects which respond to #call(exception, options) method. Thus, a lambda can be used as a notifier as follow:

ExceptionNotifier.add_notifier :custom_notifier_name,
  ->(exception, options) { puts "Something goes wrong: #{exception.message}"}

More advanced users or third-party framework developers, also can create notifiers to be shipped in gems and take advantage of ExceptionNotification's Notifier API to standardize the various solutions out there. For this, beyond the #call(exception, options) method, the notifier class MUST BE defined under the ExceptionNotifier namespace and its name sufixed by Notifier, e.g: ExceptionNotifier::SimpleNotifier.

Example

Define the custom notifier:

module ExceptionNotifier
  class SimpleNotifier
    def initialize(options)
      # do something with the options...
    end

    def call(exception, options={})
      # send the notification
    end
  end
end

Using it:

Rails.application.config.middleware.use ExceptionNotification::Rack,
                                        email: {
                                          email_prefix: '[PREFIX] ',
                                          sender_address: %{"notifier" <[email protected]>},
                                          exception_recipients: %w{[email protected]}
                                        },
                                        simple: {
                                          # simple notifier options
                                        }