@Override public boolean delete(Path path, boolean recursive) throws IOException { Preconditions.checkArgument(recursive, "Non-recursive is not supported."); String fileId = toFileId(path); LOG.debug("Deleting file: " + fileId); try { client.files().delete(fileId).execute(); } catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); if (404 == error.getCode()) { //Non-existing file id return false; } throw e; } return true; }
} catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); if (404 == error.getCode()) { throw new FileNotFoundException("File not found. Request: " + request);
private static ExceptionData makeExceptionData( GoogleJsonError googleJsonError, boolean idempotent, Set<BaseServiceException.Error> retryableErrors) { int code = googleJsonError.getCode(); String reason = reason(googleJsonError); ExceptionData.Builder exceptionData = ExceptionData.newBuilder(); exceptionData .setMessage(googleJsonError.getMessage()) .setCause(null) .setRetryable(BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors)) .setCode(code) .setReason(reason); if (reason != null) { GoogleJsonError.ErrorInfo errorInfo = googleJsonError.getErrors().get(0); exceptionData.setLocation(errorInfo.getLocation()); exceptionData.setDebugInfo((String) errorInfo.get("debugInfo")); } else { exceptionData.setLocation(null); exceptionData.setDebugInfo(null); } return exceptionData.build(); }
if (jsonError != null) { BaseServiceException.Error error = new BaseServiceException.Error(jsonError.getCode(), reason(jsonError)); code = error.getCode(); reason = error.getReason();
public static Bucket createInProject(Storage storage, String project, Bucket bucket) throws IOException { try { Storage.Buckets.Insert insertBucket = storage.buckets().insert(project, bucket); return insertBucket.execute(); } catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); if (error != null && error.getCode() == HTTP_CONFLICT && error.getMessage().contains("You already own this bucket.")) { System.out.println("already exists"); return bucket; } System.err.println(error.getMessage()); throw e; } }
/** * Main demo. An Analytics service object is instantiated and then it is used to traverse and * print all the Management API entities. If any exceptions occur, they are caught and printed. * * @param args command line args. */ public static void main(String args[]) { try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); Analytics analytics = initializeAnalytics(); printManagementEntities(analytics); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
/** * Main demo. This first initializes an analytics service object. It then uses the Google * Analytics Management API to get the first profile ID for the authorized user. It then uses the * Core Reporting API to retrieve the top 25 organic search terms. Finally the results are printed * to the screen. If an API error occurs, it is printed here. * * @param args command line args. */ public static void main(String[] args) { try { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR); Analytics analytics = initializeAnalytics(); String profileId = getFirstProfileId(analytics); if (profileId == null) { System.err.println("No profiles found."); } else { GaData gaData = executeDataQuery(analytics, profileId); printGaData(gaData); } } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
/** * Main demo. This first initializes an analytics service object. It then uses the MCF API to * retrieve the top 25 source paths with most total conversions. It will also retrieve the top 25 * organic sources with most total conversions. Finally the results are printed to the screen. If * an API error occurs, it is printed here. * * @param args command line args. */ public static void main(String[] args) { try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); Analytics analytics = initializeAnalytics(); McfData mcfPathData = executePathQuery(analytics, TABLE_ID); printAllInfo(mcfPathData); McfData mcfInteractionData = executeInteractionQuery(analytics, TABLE_ID); printAllInfo(mcfInteractionData); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
/** * Determines if the given GoogleJsonError indicates 'item not found'. */ public boolean itemNotFound(GoogleJsonError e) { return e.getCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND; }
/** * Determines if the given GoogleJsonError indicates 'precondition not met' */ public boolean preconditionNotMet(GoogleJsonError e) { return e.getCode() == STATUS_CODE_PRECONDITION_FAILED; }
/** * Determines if the given GoogleJsonError indicates 'item not found'. */ public boolean itemNotFound(GoogleJsonError e) { return e.getCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND; }
/** * Main demo. This first initializes an Analytics service object. It then queries for the top 25 * organic search keywords and traffic sources by visits. Finally each important part of the * response is printed to the screen. * * @param args command line args. */ public static void main(String[] args) { try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); Analytics analytics = initializeAnalytics(); GaData gaData = executeDataQuery(analytics, TABLE_ID); printReportInfo(gaData); printProfileInfo(gaData); printQueryInfo(gaData); printPaginationInfo(gaData); printTotalsForAllResults(gaData); printColumnHeaders(gaData); printDataTable(gaData); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
@Override public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException { if (e.getCode() == 404) { LOG.info( "Ignoring failed deletion of file {} which already does not exist: {}", file, e); } else { throw new IOException(String.format("Error trying to delete %s: %s", file, e)); } } });
/** Determines if the given GoogleJsonError indicates that 'userProject' is missing in request */ public boolean userProjectMissing(GoogleJsonError e) { ErrorInfo errorInfo = getErrorInfo(e); return errorInfo != null && e.getCode() == STATUS_CODE_BAD_REQUEST && USER_PROJECT_MISSING.equals(errorInfo.getMessage()); }
/** Determines if the given GoogleJsonError indicates that 'userProject' is missing in request */ public boolean userProjectMissing(GoogleJsonError e) { ErrorInfo errorInfo = getErrorInfo(e); return errorInfo != null && e.getCode() == STATUS_CODE_BAD_REQUEST && USER_PROJECT_MISSING.equals(errorInfo.getMessage()); }
@Override public void onFailure( GoogleJsonError e, HttpHeaders responseHeaders) throws IOException { System.err.format("For message: %s, got error: %s\n", message.getId(), e.toPrettyString()); if (e.getCode() == TOO_MANY_CONCURRENT_REQUESTS_FOR_USER) { request.queue(batches.nextBatch, this); } }
@Override public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) { if (e.getCode() == HTTP_NOT_FOUND) { deletes.put(tuple.x(), Tuple.<Boolean, StorageException>of(Boolean.FALSE, null)); } else { deletes.put(tuple.x(), Tuple.<Boolean, StorageException>of(null, translate(e))); } } });
@Override public void onFailure(final GoogleJsonError e, final HttpHeaders responseHeaders) { log.warn(String.format("Failure deleting %s. %s", file, e.getMessage())); failures.add(new HttpResponseExceptionMappingService().map( new HttpResponseException(e.getCode(), e.getMessage()))); }
@Override public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) { if (e.getCode() == HTTP_NOT_FOUND) { gets.put(tuple.x(), Tuple.<StorageObject, StorageException>of(null, null)); } else { gets.put(tuple.x(), Tuple.<StorageObject, StorageException>of(null, translate(e))); } } });
public BatchResponse<T> addError(GoogleJsonError error) { this.errors.addAll(error.getErrors()); this.resultBuilder.addItem(BulkItem.<T>builder() .setSuccessful(false) .setStatusCode(String.valueOf(error.getCode())) .setMessage(error.getMessage()) ); return this; }