Exception: ApiResource::ConnectionError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/api_resource/exceptions.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, options = {}) ⇒ ConnectionError

Returns a new instance of ConnectionError.



8
9
10
11
12
# File 'lib/api_resource/exceptions.rb', line 8

def initialize(response, options = {})
  @response = response
  @message  = options[:message]
  @path     = options[:path]
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/api_resource/exceptions.rb', line 6

def response
  @response
end

Instance Method Details

#http_codeObject



34
35
36
# File 'lib/api_resource/exceptions.rb', line 34

def http_code
  self.class.http_code
end

#to_sObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/api_resource/exceptions.rb', line 14

def to_s
  message = "Failed."

  if response.respond_to?(:code)
    message << "  Response code = #{response.code}."
  end

  if response.respond_to?(:body)
    begin
      body = JSON.parse(response.body).pretty_inspect
    rescue
      body = "INVALID JSON: #{response.body}"
    end
    message << "\nResponse message = #{body}."
  end

  message << "\n#{@message}"
  message << "\n#{@path}"
end