module ExceptionAlarm class Middleware def initialize(app) @app = app end def call(env) @app.call(env) rescue Exception => exception if Rails.application.config.exception_alarm.enable && !ignore_exceptions.include?(exception.class.to_s) && Notifier.recipients.present? Notifier.alarm(env, exception).deliver end raise exception end protected def ignore_exceptions %w[ActiveRecord::RecordNotFound AbstractController::ActionNotFound ActionController::RoutingError] end end end