Exception: YogaPants::Connection::HTTPError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/yoga_pants/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, response = nil) ⇒ HTTPError

Returns a new instance of HTTPError.



12
13
14
15
16
17
18
19
20
# File 'lib/yoga_pants/connection.rb', line 12

def initialize(message, response = nil)
  @response    = response
  if response
    @status_code = response.status_code
    super(message + "\nBody: #{response.body}")
  else
    super(message)
  end
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/yoga_pants/connection.rb', line 11

def response
  @response
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



11
12
13
# File 'lib/yoga_pants/connection.rb', line 11

def status_code
  @status_code
end

Instance Method Details

#bodyObject



22
23
24
25
26
27
28
29
# File 'lib/yoga_pants/connection.rb', line 22

def body
  return nil if response.nil?
  @body ||= begin
    JSON.load(response.body)
  rescue MultiJson::DecodeError
    response.body
  end
end