class Camdram::Error::CamdramError

Error class for Camdram API calls

Attributes

error[R]
error_description[R]
http_headers[R]
http_status_code[R]
response_body[R]

Public Class Methods

new(code, body, headers) click to toggle source
Calls superclass method
# File lib/camdram/error.rb, line 14
def initialize(code, body, headers)
  @http_status_code = code
  @response_body = body
  @http_headers = headers

  # Camdram doesn't always return errors in JSON format
  # and when it does, the format is sometimes inconsistent
  begin
    error_hash = JSON.parse(@response_body)
    @error = error_hash['error']
    @error_description = error_hash['error_description']
  rescue JSON::ParserError => e
    # FIXME come up with a better solution for this
    @error = http_status_code
    @error_description = response_body
  end
  message = "#{error}: #{error_description}"
  super(message)
  raise self
end