Module: XporterOnDemand::ExceptionFactory

Defined in:
lib/xporter_on_demand/exception_factory.rb

Class Method Summary collapse

Class Method Details

.generate_exception(response_hash) ⇒ Object

Raises:



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/xporter_on_demand/exception_factory.rb', line 3

def self.generate_exception(response_hash)
  exception_type    = response_hash.delete('ExceptionType') || "UnknownError"
  message           = response_hash.delete('Message')
  exception_message = response_hash.delete('ExceptionMessage')
  inner_exception   = response_hash.delete('InnerException')

  unless XporterOnDemand.constants.include? exception_type.to_sym
    XporterOnDemand.const_set exception_type, Class.new(Error)
  end

  blob = <<~ERROR
  #{exception_type}
  ==========
  Message: #{message}
  ExceptionMessage: #{exception_message}
  InnerException: #{inner_exception}
  ==========
  ERROR

  raise XporterOnDemand.const_get(exception_type).new(blob)
end