Exception: CartoDB::Client::Error

Inherits:
Exception
  • Object
show all
Defined in:
lib/cartodb-rb-client/cartodb/client/error.rb

Constant Summary collapse

HTTP_MESSAGES =
{
  401 => 'Unauthorized request',
  404 => 'Not found',
  500 => 'Server error'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri = nil, method = nil, http_response = nil, error_message = nil) ⇒ Error

Returns a new instance of Error.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cartodb-rb-client/cartodb/client/error.rb', line 12

def initialize(uri = nil, method = nil, http_response = nil, error_message = nil)
  @uri            = uri
  @method         = method
  @error_messages = ['undefined CartoDB error']
  @status_code    = 400
  @error_messages = [uri] if method == nil && http_response == nil && error_message == nil
  @error_messages = [error_message] if error_message

  if http_response
    @status_code = http_response.code
    @error_messages = custom_error(http_response) || standard_error
    @body = http_response.body
  end

end

Instance Attribute Details

#status_codeObject

Returns the value of attribute status_code.



4
5
6
# File 'lib/cartodb-rb-client/cartodb/client/error.rb', line 4

def status_code
  @status_code
end

Instance Method Details

#custom_error(http_response) ⇒ Object



44
45
46
47
# File 'lib/cartodb-rb-client/cartodb/client/error.rb', line 44

def custom_error(http_response)
  json = Utils.parse_json(http_response)
  json[:error] if json
end

#to_sObject



28
29
30
31
32
33
34
35
# File 'lib/cartodb-rb-client/cartodb/client/error.rb', line 28

def to_s
  message = <<-EOF
    #{http_error_message_header}
    #{format_error_messages}
    #{@body}
  EOF
  message.strip
end