Method: Aspera::RestErrorAnalyzer#raise_on_error

Defined in:
lib/aspera/rest_error_analyzer.rb

#raise_on_error(req, res) ⇒ Object

Use this method to analyze a EST result and raise an exception Analyzes REST call response and raises a RestCallError exception if HTTP result code is not 2XX

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/aspera/rest_error_analyzer.rb', line 29

def raise_on_error(req, res)
  Log.log.debug{"raise_on_error #{req.method} #{req.path} #{res[:http].code}"}
  call_context = {
    messages: [],
    request:  req,
    response: res[:http],
    data:     res[:data]
  }
  # multiple error messages can be found
  # analyze errors from provided handlers
  # note that there can be an error even if code is 2XX
  @error_handlers.each do |handler|
    begin # rubocop:disable Style/RedundantBegin
      # Log.log.debug{"test exception: #{handler[:name]}"}
      handler[:block].call(handler[:name], call_context)
    rescue StandardError => e
      Log.log.error{"ERROR in handler:\n#{e.message}\n#{e.backtrace}"}
    end
  end
  raise RestCallError.new(call_context[:messages].join("\n"), call_context[:request], call_context[:response]) unless call_context[:messages].empty?
end