Exception: Webceo::Api::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Webceo::Api::Error
- Defined in:
- lib/webceo/api/error.rb
Overview
Class Error provides customized error message based on the response sent by Webceo API server
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_method ⇒ Object
Returns the value of attribute api_method.
-
#code ⇒ Object
Returns the value of attribute code.
-
#http_status ⇒ Object
Returns the value of attribute http_status.
-
#message ⇒ Object
Returns the value of attribute message.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
Instance Method Summary collapse
-
#initialize(http_status, response_body, error_info = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(http_status, response_body, error_info = nil) ⇒ Error
Returns a new instance of Error.
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 |
# File 'lib/webceo/api/error.rb', line 13 def initialize(http_status, response_body, error_info = nil) self.response_body = (response_body) ? response_body.strip : '' 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).first if response_body rescue end error_info ||= {} end error_info = error_info.with_indifferent_access self.code = error_info['result'] self. = error_info['errormsg'] self.api_method = error_info['method'] self.request_id = error_info['id'] error_array = [] %i(code message api_method request_id).each do |key| error_array << "#{key}: #{self.send(key)}" if self.send(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
#api_method ⇒ Object
Returns the value of attribute api_method.
11 12 13 |
# File 'lib/webceo/api/error.rb', line 11 def api_method @api_method end |
#code ⇒ Object
Returns the value of attribute code.
11 12 13 |
# File 'lib/webceo/api/error.rb', line 11 def code @code end |
#http_status ⇒ Object
Returns the value of attribute http_status.
11 12 13 |
# File 'lib/webceo/api/error.rb', line 11 def http_status @http_status end |
#message ⇒ Object
Returns the value of attribute message.
11 12 13 |
# File 'lib/webceo/api/error.rb', line 11 def @message end |
#request_id ⇒ Object
Returns the value of attribute request_id.
11 12 13 |
# File 'lib/webceo/api/error.rb', line 11 def request_id @request_id end |
#response_body ⇒ Object
Returns the value of attribute response_body.
11 12 13 |
# File 'lib/webceo/api/error.rb', line 11 def response_body @response_body end |