Exception: QuickTravel::AdapterError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/quick_travel/adapter_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ AdapterError

Returns a new instance of AdapterError.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/quick_travel/adapter_error.rb', line 6

def initialize(response)
  case response
    when String
      @response = { 'error' => response }
      @status = 422
    when HTTParty::Response
      @response = response.parsed_response
      @status = response.code
    else
      fail "Unexpected response type #{response.class}"\
           "Should be String or HTTParty::Response"
  end

  error_message = if @response.is_a? Hash
    @response.fetch('error', "We're sorry, but something went wrong. Please call us.")
  else
    @response
  end
  super(error_message)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/quick_travel/adapter_error.rb', line 3

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/quick_travel/adapter_error.rb', line 4

def status
  @status
end

Instance Method Details

#error_typeObject



27
28
29
# File 'lib/quick_travel/adapter_error.rb', line 27

def error_type
  @response.fetch('error_type', 'unspecified')
end