class Attio::OAuth::Client

def handle_oauth_error(response)

def handle_oauth_error(response)
  error_body = begin
    response.body
  rescue
    {}
  end
  error_message = if error_body.is_a?(Hash)
    error_body[:error_description] || error_body[:error] || "OAuth error"
  else
    "OAuth error"
  end
  case response.status
  when 400
    raise BadRequestError, error_message
  when 401
    raise AuthenticationError, error_message
  when 403
    raise ForbiddenError, error_message
  when 404
    raise NotFoundError, error_message
  else
    raise Error, "OAuth error: #{error_message} (status: #{response.status})"
  end
end