Sha256: 2041f14ba12fa9eae2eed3fce05d4fc303e9712bd2d91ed7a74987ab10af0fe4

Contents?: true

Size: 855 Bytes

Versions: 4

Compression:

Stored size: 855 Bytes

Contents

# frozen_string_literal: true

module AnyCable
  module ExceptionsHandling # :nodoc:
    class << self
      def add_handler(block)
        handlers << procify(block)
      end

      alias << add_handler

      def notify(exp, method_name, message)
        handlers.each do |handler|
          begin
            handler.call(exp, method_name, message)
          rescue StandardError => exp
            AnyCable.logger.error "!!! EXCEPTION HANDLER THREW AN ERROR !!!"
            AnyCable.logger.error exp
            AnyCable.logger.error exp.backtrace.join("\n") unless exp.backtrace.nil?
          end
        end
      end

      private

      def procify(block)
        return block unless block.lambda?

        proc { |*args| block.call(*args.take(block.arity)) }
      end

      def handlers
        @handlers ||= []
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
anycable-0.6.5 lib/anycable/exceptions_handling.rb
anycable-0.6.4 lib/anycable/exceptions_handling.rb
anycable-0.6.3 lib/anycable/exceptions_handling.rb
anycable-0.6.2 lib/anycable/exceptions_handling.rb