Sha256: a67684e207f135e7f1ba315a21a119a2c730ce772d22f6488275d83bd2796b8a

Contents?: true

Size: 1.6 KB

Versions: 4

Compression:

Stored size: 1.6 KB

Contents

require 'action_dispatch'

module ExceptionNotifier
  class WebhookNotifier < BaseNotifier

    def initialize(options)
      super
      @default_options = options
    end

    def call(exception, options={})
      env = options[:env]

      options = options.reverse_merge(@default_options)
      url = options.delete(:url)
      http_method = options.delete(:http_method) || :post

      options[:body] ||= {}
      options[:body][:server] = Socket.gethostname
      options[:body][:process] = $$
      if defined?(Rails) && Rails.respond_to?(:root)
        options[:body][:rails_root] = Rails.root
      end
      options[:body][:exception] = {:error_class => exception.class.to_s,
                                    :message => exception.message.inspect,
                                    :backtrace => exception.backtrace}
      options[:body][:data] = (env && env['exception_notifier.exception_data'] || {}).merge(options[:data] || {})

      unless env.nil?
        request = ActionDispatch::Request.new(env)

        request_items = {:url => request.original_url,
                         :http_method => request.method,
                         :ip_address => request.remote_ip,
                         :parameters => request.filtered_parameters,
                         :timestamp => Time.current }

        options[:body][:request] = request_items
        options[:body][:session] = request.session
        options[:body][:environment] = request.filtered_env
      end
      send_notice(exception, options, nil, @default_options) do |msg, opts|
        HTTParty.send(http_method, url, opts)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
exception_notification_more_info-1.0.1 lib/exception_notifier/webhook_notifier.rb
exception_notification_more_info-1.0.0 lib/exception_notifier/webhook_notifier.rb
exception_notification-4.1.4 lib/exception_notifier/webhook_notifier.rb
exception_notification-4.1.3 lib/exception_notifier/webhook_notifier.rb