Exception: StatusPage::API::Exception
- Inherits:
-
StandardError
- Object
- StandardError
- StatusPage::API::Exception
- Defined in:
- lib/status_page/api/exception.rb
Instance Attribute Summary collapse
-
#rest_client_error ⇒ Object
readonly
Returns the value of attribute rest_client_error.
Instance Method Summary collapse
-
#initialize(rest_client_error) ⇒ Exception
constructor
A new instance of Exception.
-
#message ⇒ Object
generates message from original error and JSON response.
-
#response ⇒ Object
parses error from JSON response if possible if invalid JSON, or JSON missing “error” key, returns full JSON string.
Constructor Details
#initialize(rest_client_error) ⇒ Exception
Returns a new instance of Exception.
6 7 8 9 |
# File 'lib/status_page/api/exception.rb', line 6 def initialize(rest_client_error) @rest_client_error = rest_client_error super() end |
Instance Attribute Details
#rest_client_error ⇒ Object (readonly)
Returns the value of attribute rest_client_error.
4 5 6 |
# File 'lib/status_page/api/exception.rb', line 4 def rest_client_error @rest_client_error end |
Instance Method Details
#message ⇒ Object
generates message from original error and JSON response
12 13 14 |
# File 'lib/status_page/api/exception.rb', line 12 def "#{rest_client_error.} (#{response})" end |
#response ⇒ Object
parses error from JSON response if possible if invalid JSON, or JSON missing “error” key, returns full JSON string
18 19 20 21 22 23 24 25 26 |
# File 'lib/status_page/api/exception.rb', line 18 def response return "NO RESPONSE" unless rest_client_error.response error_text = JSON.parse(rest_client_error.response)["error"] error_text.is_a?(Array) ? error_text.join(", ") : error_text rescue JSON::ParserError rest_client_error.response rescue NoMethodError rest_client_error.response end |