Java Code Examples for com.google.api.client.googleapis.json.GoogleJsonError#getMessage()

The following examples show how to use com.google.api.client.googleapis.json.GoogleJsonError#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncRequest.java    From connector-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Wrapper on {@link JsonBatchCallback#onFailure} to record failure while executing batched
 * request.
 */
@Override
public void onFailure(GoogleJsonError error, HttpHeaders responseHeaders) {
  if (event != null) {
    event.failure();
    event = null;
  } else {
    operationStats.event(request.requestToExecute.getClass().getName()).failure();
  }
  logger.log(Level.WARNING, "Request failed with error {0}", error);
  if (request.retryPolicy.isRetryableStatusCode(error.getCode())) {
    if (request.getRetries() < request.retryPolicy.getMaxRetryLimit()) {
      request.setStatus(Status.RETRYING);
      request.incrementRetries();
      return;
    }
  }
  GoogleJsonResponseException exception =
      new GoogleJsonResponseException(
          new Builder(error.getCode(), error.getMessage(), responseHeaders), error);
  fail(exception);
}
 
Example 2
Source File: IndexingServiceTest.java    From connector-sdk with Apache License 2.0 5 votes vote down vote up
private static <T> ListenableFuture<T> getExceptionFuture(GoogleJsonError e) {
  SettableFuture<T> settable = SettableFuture.create();
  GoogleJsonResponseException exception =
      new GoogleJsonResponseException(
          new Builder(e.getCode(), e.getMessage(), new HttpHeaders()), e);
  settable.setException(exception);
  return settable;
}
 
Example 3
Source File: GcsDataflowProjectClient.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the provided specification for the staging location, creating it if it does not already
 * exist. This may be a long-running blocking operation.
 */
public StagingLocationVerificationResult createStagingLocation(
    String projectId, String stagingLocation, IProgressMonitor progressMonitor) {
  SubMonitor monitor = SubMonitor.convert(progressMonitor, 2);
  String bucketName = toGcsBucketName(stagingLocation);
  if (locationIsAccessible(stagingLocation)) { // bucket already exists
    return new StagingLocationVerificationResult(
        String.format("Bucket %s exists", bucketName), true);
  }
  monitor.worked(1);

  // else create the bucket
  try {
    Bucket newBucket = new Bucket();
    newBucket.setName(bucketName);
    gcsClient.buckets().insert(projectId, newBucket).execute();
    return new StagingLocationVerificationResult(
        String.format("Bucket %s created", bucketName), true);
  } catch (GoogleJsonResponseException ex) {
    GoogleJsonError error = ex.getDetails();
    return new StagingLocationVerificationResult(error.getMessage(), false);
  } catch (IOException e) {
    return new StagingLocationVerificationResult(e.getMessage(), false);
  } finally {
    monitor.done();
  }
}
 
Example 4
Source File: BigqueryJobFailureException.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/** Create an error for JSON server response errors. */
public static BigqueryJobFailureException create(GoogleJsonResponseException cause) {
  GoogleJsonError err = cause.getDetails();
  if (err != null) {
    return new BigqueryJobFailureException(err.getMessage(), null, null, err);
  } else {
    return new BigqueryJobFailureException(cause.getMessage(), cause, null, null);
  }
}
 
Example 5
Source File: GoogleCloudStorageExceptions.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
public static GoogleJsonResponseException createJsonResponseException(
    GoogleJsonError e, HttpHeaders responseHeaders) {
  if (e != null) {
    return new GoogleJsonResponseException(
        new HttpResponseException.Builder(e.getCode(), e.getMessage(), responseHeaders), e);
  }
  return null;
}
 
Example 6
Source File: CloudEndpointUtils.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * Logs the given throwable and shows an error alert dialog with its
 * message.
 * 
 * @param activity activity
 * @param tag log tag to use
 * @param t throwable to log and show
 */
public static void logAndShow(Activity activity, String tag, Throwable t) {
    Log.e(tag, "Error", t);
    String message = t.getMessage();
    if (t instanceof GoogleJsonResponseException) {
        GoogleJsonError details = ((GoogleJsonResponseException) t).getDetails();
        if (details != null) {
            message = details.getMessage();
        }
    }
    showError(activity, message);
}
 
Example 7
Source File: Utils.java    From SimplePomodoro-android with MIT License 5 votes vote down vote up
/**
 * Logs the given throwable and shows an error alert dialog with its message.
 * 
 * @param activity activity
 * @param tag log tag to use
 * @param t throwable to log and show
 */
public static void logAndShow(Activity activity, String tag, Throwable t) {
  Log.e(tag, "Error", t);
  String message = t.getMessage();
  if (t instanceof GoogleJsonResponseException) {
    GoogleJsonError details = ((GoogleJsonResponseException) t).getDetails();
    if (details != null) {
      message = details.getMessage();
    }
  } else if (t.getCause() instanceof GoogleAuthException) {
    message = ((GoogleAuthException) t.getCause()).getMessage();
  }
  showError(activity, message);
}
 
Example 8
Source File: CloudEndpointUtils.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 5 votes vote down vote up
/**
 * Logs the given throwable and shows an error alert dialog with its
 * message.
 * 
 * @param activity
 *            activity
 * @param tag
 *            log tag to use
 * @param t
 *            throwable to log and show
 */
public static void logAndShow(Activity activity, String tag, Throwable t) {
  Log.e(tag, "Error", t);
  String message = t.getMessage();
  // Exceptions that occur in your Cloud Endpoint implementation classes
  // are wrapped as GoogleJsonResponseExceptions
  if (t instanceof GoogleJsonResponseException) {
    GoogleJsonError details = ((GoogleJsonResponseException) t)
        .getDetails();
    if (details != null) {
      message = details.getMessage();
    }
  }
  showError(activity, message);
}
 
Example 9
Source File: ApiErrorExtractor.java    From hadoop-connectors with Apache License 2.0 4 votes vote down vote up
/** Extracts the error message. */
public String getErrorMessage(IOException e) {
  // Prefer to use message from GJRE.
  GoogleJsonError jsonError = getJsonError(e);
  return jsonError == null ? e.getMessage() : jsonError.getMessage();
}