Class: HaveAPI::Extensions::ActionExceptions

Inherits:
Base
  • Object
show all
Defined in:
lib/haveapi/extensions/action_exceptions.rb

Class Method Summary collapse

Class Method Details

.enabled(server) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/haveapi/extensions/action_exceptions.rb', line 6

def enabled(server)
  HaveAPI::Action.connect_hook(:exec_exception) do |ret, _context, e|
    break(ret) unless @exceptions

    @exceptions.each do |handler|
      if e.is_a?(handler[:klass])
        ret = handler[:block].call(ret, e)
        break
      end
    end

    ret
  end
end

.rescue(klass, &block) ⇒ Object



21
22
23
24
# File 'lib/haveapi/extensions/action_exceptions.rb', line 21

def rescue(klass, &block)
  @exceptions ||= []
  @exceptions << { klass:, block: }
end