class StatusPage::API::Exception

Attributes

rest_client_error[R]

Public Class Methods

new(rest_client_error) click to toggle source
Calls superclass method
# File lib/status_page/api/exception.rb, line 6
def initialize(rest_client_error)
  @rest_client_error = rest_client_error
  super(message)
end

Public Instance Methods

message() click to toggle source

generates message from original error and JSON response

# File lib/status_page/api/exception.rb, line 12
def message
  "#{rest_client_error.message} (#{response})"
end
response() click to toggle source

parses error from JSON response if possible if invalid JSON, or JSON missing “error” key, returns full JSON string

# 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