Class: Apress::Api::Callbacks::BaseCallback

Inherits:
Object
  • Object
show all
Includes:
Interactor
Defined in:
app/interactors/apress/api/callbacks/base_callback.rb

Class Method Summary collapse

Class Method Details

.add_repeat_exceptions(*errors) ⇒ Object



20
21
22
23
# File 'app/interactors/apress/api/callbacks/base_callback.rb', line 20

def self.add_repeat_exceptions(*errors)
  repeat_exceptions.merge(errors)
  retry_exceptions.merge(errors)
end

.add_retry_exceptions(*errors) ⇒ Object



16
17
18
# File 'app/interactors/apress/api/callbacks/base_callback.rb', line 16

def self.add_retry_exceptions(*errors)
  retry_exceptions.merge(errors)
end

.inherited(other) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/interactors/apress/api/callbacks/base_callback.rb', line 25

def self.inherited(other)
  other.around do |interactor|
    begin
      interactor.call
    rescue Exception => error
      if self.class.repeat_exceptions.any? { |ex| ex === error }
        raise Apress::Api::Callbacks::RepeatCallbackError.new(error.message, error.backtrace)
      elsif self.class.retry_exceptions.any? { |ex| error.is_a?(Class) && ex >= error || ex === error }
        raise Apress::Api::Callbacks::FireCallbackError.new(error.message, error.backtrace)
      else
        raise error
      end
    end
  end
end

.repeat_exceptionsObject



12
13
14
# File 'app/interactors/apress/api/callbacks/base_callback.rb', line 12

def self.repeat_exceptions
  @repeat_exceptions ||= Set.new
end

.retry_exceptionsObject



8
9
10
# File 'app/interactors/apress/api/callbacks/base_callback.rb', line 8

def self.retry_exceptions
  @retry_exceptions ||= Set.new
end