Exception: EDH::Passport::APIError
- Defined in:
- lib/edh/errors.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#http_status ⇒ Object
Returns the value of attribute http_status.
-
#pp_error_code ⇒ Object
Returns the value of attribute pp_error_code.
-
#pp_error_message ⇒ Object
Returns the value of attribute pp_error_message.
-
#pp_error_subcode ⇒ Object
Returns the value of attribute pp_error_subcode.
-
#pp_error_type ⇒ Object
Returns the value of attribute pp_error_type.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
Instance Method Summary collapse
-
#initialize(http_status, response_body, error_info = nil) ⇒ Object
constructor
Create a new API Error.
Constructor Details
#initialize(http_status, response_body, error_info = nil) ⇒ Object
Create a new API Error
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 54 55 56 57 58 59 60 61 |
# File 'lib/edh/errors.rb', line 23 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.pp_error_type = error_info["type"] self.pp_error_code = error_info["code"] self.pp_error_subcode = error_info["error_subcode"] self. = error_info["message"] error_array = [] %w(type code error_subcode message).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
#http_status ⇒ Object
Returns the value of attribute http_status.
8 9 10 |
# File 'lib/edh/errors.rb', line 8 def http_status @http_status end |
#pp_error_code ⇒ Object
Returns the value of attribute pp_error_code.
8 9 10 |
# File 'lib/edh/errors.rb', line 8 def pp_error_code @pp_error_code end |
#pp_error_message ⇒ Object
Returns the value of attribute pp_error_message.
8 9 10 |
# File 'lib/edh/errors.rb', line 8 def @pp_error_message end |
#pp_error_subcode ⇒ Object
Returns the value of attribute pp_error_subcode.
8 9 10 |
# File 'lib/edh/errors.rb', line 8 def pp_error_subcode @pp_error_subcode end |
#pp_error_type ⇒ Object
Returns the value of attribute pp_error_type.
8 9 10 |
# File 'lib/edh/errors.rb', line 8 def pp_error_type @pp_error_type end |
#response_body ⇒ Object
Returns the value of attribute response_body.
8 9 10 |
# File 'lib/edh/errors.rb', line 8 def response_body @response_body end |