class GatherContent::Error::RequestError

Attributes

response[R]
status[R]

Public Class Methods

new(response) click to toggle source
Calls superclass method
# File lib/gather_content/error/request_error.rb, line 6
def initialize(response)
  @response = response
  @status = response.status

  super(parse_message(response))
end

Private Instance Methods

parse_message(response) click to toggle source
# File lib/gather_content/error/request_error.rb, line 14
def parse_message(response)
  parsed = JSON.parse(response.body)

  return response.body unless parsed.is_a?(Hash)
  return parsed['data'].join(' ') if parsed['data'].is_a?(Array)

  if parsed.is_a?(Hash) && parsed['data']
    data = parsed['data']

    return data['message'] if data['message']
    return data.to_s
  elsif parsed.is_a?(Hash) && parsed['error']
    parsed['error']
  else
    parsed['data'].to_s
  end
end