Exception: StatusPage::API::Exception

Inherits:
StandardError
  • Object
show all
Defined in:
lib/status_page/api/exception.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(message)
end

Instance Attribute Details

#rest_client_errorObject (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

#messageObject

generates message from original error and JSON response



12
13
14
# File 'lib/status_page/api/exception.rb', line 12

def message
  "#{rest_client_error.message} (#{response})"
end

#responseObject

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