Exception: Redox::RedoxException

Inherits:
Exception
  • Object
show all
Defined in:
lib/redox/redox_exception.rb

Class Method Summary collapse

Class Method Details

.from_response(response, msg: nil) ⇒ Object



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

def self.from_response(response, msg: nil)
  exception_msg = "Failed #{msg}:"
  exception_msg << " HTTP code: #{response&.code} MSG: "

  begin
    error_response = response.parsed_response
    error_list = error_response&.[]('Meta')&.[]('Errors')

    if error_list
      exception_msg << error_list.map {|el| el['Text'] || el.to_s }.join('|')
    else
      exception_msg << error_response.to_s
    end
  rescue JSON::ParserError
    exception_msg << response.body
  end

  return RedoxException.new(exception_msg)
end