Class: HaveAPI::Extensions::ActionExceptions

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

Class Method Summary collapse

Class Method Details

.enabledObject



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

def enabled
  HaveAPI::Action.connect_hook(:exec_exception) do |ret, action, 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



19
20
21
22
# File 'lib/haveapi/extensions/action_exceptions.rb', line 19

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