code: public static HttpResponse execute(JsonFactory jsonFactory, HttpRequest request)
        throws GoogleJsonResponseException, IOException {
      Preconditions.checkNotNull(jsonFactory);
      boolean originalThrowExceptionOnExecuteError = request.getThrowExceptionOnExecuteError();
      if (originalThrowExceptionOnExecuteError) {
        request.setThrowExceptionOnExecuteError(false);
      }
      HttpResponse response = request.execute();
      request.setThrowExceptionOnExecuteError(originalThrowExceptionOnExecuteError);
      if (!originalThrowExceptionOnExecuteError || response.isSuccessStatusCode()) {
        return response;
      }
      throw GoogleJsonResponseException.from(jsonFactory, response);
    }
docs: Executes an HTTP request using {@link HttpRequest#execute()}, but throws a
  {@link GoogleJsonResponseException} on error instead of {@link HttpResponseException}.
  
  <p>
  Callers should call {@link HttpResponse#disconnect} when the returned HTTP response object is
  no longer needed. However, {@link HttpResponse#disconnect} does not have to be called if the
  response stream is properly closed. Example usage:
  </p>
  
  <pre>
  HttpResponse response = GoogleJsonResponseException.execute(jsonFactory, request);
  try {
  process the HTTP response object
  } finally {
  response.disconnect();
  }
  </pre>
  
  @param jsonFactory JSON factory
  @param request HTTP request
  @return HTTP response for an HTTP success code (or error code if
  {@link HttpRequest#getThrowExceptionOnExecuteError()})
  @throws GoogleJsonResponseException for an HTTP error code (only if not
  {@link HttpRequest#getThrowExceptionOnExecuteError()})
  @throws IOException some other kind of I/O exception
  @since 1.7