module Outreach::Errors

Public Instance Methods

check_for_error(status_code, response_body) click to toggle source
# File lib/outreach/errors.rb, line 7
def check_for_error(status_code, response_body)
  response_hash = JSON.parse(response_body)
  if response_hash['errors'].present? &&
      response_hash['errors']['status'].present?
    status_code = response_hash['errors']['status']
  end

  # raise error if status code isn't 200
  case status_code.to_i
  when 401
    unauthorized_error(response_body)
  end
end

Private Instance Methods

unauthorized_error(response_body) click to toggle source
# File lib/outreach/errors.rb, line 23
def unauthorized_error(response_body)
  description = begin
    JSON.parse(response_body).fetch("error_description")
  rescue
    "Unauthorized"
  end
  raise Unauthorized.new(description)
end