def error(response)
      if response.body && response.body.match("missing client token")
        raise MissingTokenError
      end

      # Use the correct exception class
      case response
      when Net::HTTPClientError
        klass = HTTPClientError
      when Net::HTTPServerError
        klass = HTTPServerError
      else
        klass = HTTPError
      end

      if (response.content_type || '').include?("json")
        # Attempt to parse the error as JSON
        begin
          json = JSON.parse(response.body, JSON_PARSE_OPTIONS)

          if json[:errors]
            raise klass.new(address, response, json[:errors])
          end
        rescue JSON::ParserError; end
      end

      raise klass.new(address, response, [response.body])
    end
def error(response)
      if response.body && response.body.match("missing client token")
        raise MissingTokenError
      end

      # Use the correct exception class
      case response
      when Net::HTTPClientError
        klass = HTTPClientError
      when Net::HTTPServerError
        klass = HTTPServerError
      else
        klass = HTTPError
      end

      if (response.content_type || '').include?("json")
        # Attempt to parse the error as JSON
        begin
          json = JSON.parse(response.body, JSON_PARSE_OPTIONS)

          if json[:errors]
            raise klass.new(address, response, json[:errors])
          end
        rescue JSON::ParserError; end
      end

      raise klass.new(address, response, [response.body])
    end
Raise a response error, extracting as much information from the server's
 response as possible.

 @raise [HTTPError]

 @param [HTTP::Message] response
   the response object from the request