Class: GorgService::Consumer::MessageHandler::ExceptionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/gorg_service/consumer/message_handler/exception_manager.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



9
10
11
# File 'lib/gorg_service/consumer/message_handler/exception_manager.rb', line 9

def self.instance
  @instance ||= self.new
end

Instance Method Details

#get_rescue_block_for(exception) ⇒ Object



38
39
40
# File 'lib/gorg_service/consumer/message_handler/exception_manager.rb', line 38

def get_rescue_block_for(exception)
  exceptions_hash.find{|k,_v| exception.is_a?(k)}[1]
end

#rescuable_exceptionsObject



34
35
36
# File 'lib/gorg_service/consumer/message_handler/exception_manager.rb', line 34

def rescuable_exceptions
  exceptions_hash.keys
end

#set_rescue_from(*exception_classes, &block) ⇒ Object



28
29
30
31
32
# File 'lib/gorg_service/consumer/message_handler/exception_manager.rb', line 28

def set_rescue_from(*exception_classes,&block)
  exception_classes.each do |e|
    exceptions_hash[e]=block
  end
end

#with_exception_rescuing(message = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gorg_service/consumer/message_handler/exception_manager.rb', line 13

def with_exception_rescuing(message=nil)
  begin
    begin
      yield
    rescue *rescuable_exceptions => e
      get_rescue_block_for(e).call(e,message)
    end
  rescue GorgService::Consumer::FailError => e
    raise e
  # rescue StandardError => e
  #   GorgService.logger.error "Uncaught exception : #{e.inspect}"
  #   raise HardfailError.new("UncaughtException", e)
  end
end