Exception: Camdram::Error::CamdramError

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

Overview

Error class for Camdram API calls

Direct Known Subclasses

ClientError, RedirectError, ServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, body, headers) ⇒ CamdramError

Returns a new instance of CamdramError.

Raises:

  • (self)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#error_descriptionObject (readonly)

Returns the value of attribute error_description.



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

def error_description
  @error_description
end

#http_headersObject (readonly)

Returns the value of attribute http_headers.



11
12
13
# File 'lib/camdram/error.rb', line 11

def http_headers
  @http_headers
end

#http_status_codeObject (readonly)

Returns the value of attribute http_status_code.



11
12
13
# File 'lib/camdram/error.rb', line 11

def http_status_code
  @http_status_code
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



11
12
13
# File 'lib/camdram/error.rb', line 11

def response_body
  @response_body
end