Exception: Azimuth::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/azimuth/error.rb

Overview

Custom error class

Class Method Summary collapse

Class Method Details

.from_response(response) ⇒ Azimuth::Error

Returns the Error based on status and response message.

Parameters:

  • response (Hash)

    HTTP response

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/azimuth/error.rb', line 10

def self.from_response(response)
  parsed_response_info = ::MultiJson.load(response[:body])['info']

  status_code = parsed_response_info['statuscode']

  return if status_code == 0

  if error_message = parsed_response_info['messages']
    error_message = error_message.join(' ')
  end

  case status_code
  when 400
    raise Azimuth::ErrorWithInput, error_message
  when 403
    raise Azimuth::KeyRelatedError, error_message
  when 500
    raise Azimuth::UnknownError, error_message
  when 600...699
    raise Azimuth::OtherError, error_message
  end
end