Exception: Cartowrap::APIError
- Inherits:
-
CartowrapError
- Object
- StandardError
- CartowrapError
- Cartowrap::APIError
- Defined in:
- lib/cartowrap/errors.rb
Direct Known Subclasses
BadCartodbResponse, ClientError, NoTokenError, NotFoundError, OAuthTokenRequestError, ServerError
Instance Attribute Summary collapse
-
#cdb_error_code ⇒ Object
Returns the value of attribute cdb_error_code.
-
#cdb_error_message ⇒ Object
Returns the value of attribute cdb_error_message.
-
#cdb_error_subcode ⇒ Object
Returns the value of attribute cdb_error_subcode.
-
#cdb_error_type ⇒ Object
Returns the value of attribute cdb_error_type.
-
#cdb_error_user_msg ⇒ Object
Returns the value of attribute cdb_error_user_msg.
-
#cdb_error_user_title ⇒ Object
Returns the value of attribute cdb_error_user_title.
-
#http_status ⇒ Object
Returns the value of attribute http_status.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
Instance Method Summary collapse
-
#initialize(http_status, response_body, error_info = nil) ⇒ APIError
constructor
A new instance of APIError.
Constructor Details
#initialize(http_status, response_body, error_info = nil) ⇒ APIError
Returns a new instance of APIError.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cartowrap/errors.rb', line 13 def initialize(http_status, response_body, error_info = nil) if response_body self.response_body = response_body.strip else self.response_body = '' end self.http_status = http_status if error_info && error_info.is_a?(String) = error_info else unless error_info begin error_info = MultiJson.load(response_body)['error'] if response_body rescue end error_info ||= {} end self.cdb_error_type = error_info["type"] self.cdb_error_code = error_info["code"] self.cdb_error_subcode = error_info["error_subcode"] self. = error_info["message"] self.cdb_error_user_msg = error_info["error_user_msg"] self.cdb_error_user_title = error_info["error_user_title"] error_array = [] %w(type code error_subcode message error_user_title error_user_msg).each do |key| error_array << "#{key}: #{error_info[key]}" if error_info[key] end if error_array.empty? = self.response_body else = error_array.join(', ') end end += " [HTTP #{http_status}]" if http_status super() end |
Instance Attribute Details
#cdb_error_code ⇒ Object
Returns the value of attribute cdb_error_code.
9 10 11 |
# File 'lib/cartowrap/errors.rb', line 9 def cdb_error_code @cdb_error_code end |
#cdb_error_message ⇒ Object
Returns the value of attribute cdb_error_message.
9 10 11 |
# File 'lib/cartowrap/errors.rb', line 9 def @cdb_error_message end |
#cdb_error_subcode ⇒ Object
Returns the value of attribute cdb_error_subcode.
9 10 11 |
# File 'lib/cartowrap/errors.rb', line 9 def cdb_error_subcode @cdb_error_subcode end |
#cdb_error_type ⇒ Object
Returns the value of attribute cdb_error_type.
9 10 11 |
# File 'lib/cartowrap/errors.rb', line 9 def cdb_error_type @cdb_error_type end |
#cdb_error_user_msg ⇒ Object
Returns the value of attribute cdb_error_user_msg.
9 10 11 |
# File 'lib/cartowrap/errors.rb', line 9 def cdb_error_user_msg @cdb_error_user_msg end |
#cdb_error_user_title ⇒ Object
Returns the value of attribute cdb_error_user_title.
9 10 11 |
# File 'lib/cartowrap/errors.rb', line 9 def cdb_error_user_title @cdb_error_user_title end |
#http_status ⇒ Object
Returns the value of attribute http_status.
9 10 11 |
# File 'lib/cartowrap/errors.rb', line 9 def http_status @http_status end |
#response_body ⇒ Object
Returns the value of attribute response_body.
9 10 11 |
# File 'lib/cartowrap/errors.rb', line 9 def response_body @response_body end |