Exception: FitbitClient::Error

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

Direct Known Subclasses

TokenError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, response = nil) ⇒ Error

Returns a new instance of Error.



7
8
9
10
# File 'lib/fitbit_client/error.rb', line 7

def initialize(message, response = nil)
  @message = message
  @response = response
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/fitbit_client/error.rb', line 5

def response
  @response
end

Instance Method Details

#json_responseObject



12
13
14
# File 'lib/fitbit_client/error.rb', line 12

def json_response
  @json_response ||= JSON.parse(response.body) if response
end

#to_sObject



16
17
18
19
20
21
22
# File 'lib/fitbit_client/error.rb', line 16

def to_s
  if response
    "#{@message}, HTTP_STATUS: #{response.status}, HTTP_BODY: #{response.body}, HTTP_URL: #{response.response.env.url}"
  else
    @message.to_s
  end
end