private static String message(IOException exception) { if (exception instanceof GoogleJsonResponseException) { GoogleJsonError details = ((GoogleJsonResponseException) exception).getDetails(); if (details != null) { return details.getMessage(); } } return exception.getMessage(); } }
@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; }
fileList = request.execute(); } catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); if (404 == error.getCode()) { throw new FileNotFoundException("File not found. Request: " + request);
if ( gjre.getDetails() != null && gjre.getDetails().getMessage() != null ) { exceptionToDisplay = new IOException( gjre.getDetails().getMessage(), gjre );
if (exception instanceof HttpResponseException) { if (exception instanceof GoogleJsonResponseException) { GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails(); if (jsonError != null) { BaseServiceException.Error error =
/** * 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(); } }
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; } }
List<ErrorInfo> errors = e.getDetails().getErrors(); for (ErrorInfo error : errors) { if (error.getReason().equals("noAdSenseAccount")) {
/** * 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(); } }
/** * 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(); } }
try { // Make your Google API call } catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); // Print out the message and errors }
} catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); System.err.println(error.getMessage());
public static boolean isPermissionDenied(GoogleJsonResponseException e) { return e.getStatusCode() == 403 && Optional.ofNullable(e.getDetails()) .map(GcpUtil::isPermissionDenied) .orElse(false); }
/** Extracts the error message. */ public String getErrorMessage(IOException e) { // Prefer to use message from GJRE. GoogleJsonResponseException gjre = getJsonResponseExceptionOrNull(e); if (gjre != null && gjre.getDetails() != null) { return gjre.getDetails().getMessage(); } return e.getMessage(); }
private static String message(IOException exception) { if (exception instanceof GoogleJsonResponseException) { GoogleJsonError details = ((GoogleJsonResponseException) exception).getDetails(); if (details != null) { return details.getMessage(); } } return exception.getMessage(); }
/** Extracts the error message. */ public String getErrorMessage(IOException e) { // Prefer to use message from GJRE. GoogleJsonResponseException gjre = getJsonResponseExceptionOrNull(e); if (gjre != null && gjre.getDetails() != null) { return gjre.getDetails().getMessage(); } return e.getMessage(); }
public static boolean isResourceExhausted(GoogleJsonResponseException e) { return e.getStatusCode() == 429 && Optional.ofNullable(e.getDetails()) .map(GcpUtil::isResourceExhausted) .orElse(false); }
/** * Determines if the given exception indicates that 'userProject' is missing in request. * Recursively checks getCause() if outer exception isn't an instance of the correct class. */ public boolean userProjectMissing(IOException e) { GoogleJsonResponseException jsonException = getJsonResponseExceptionOrNull(e); return jsonException != null && userProjectMissing(jsonException.getDetails()); }
private static AppEdit createEdit(App app, Edits edits) { try { // Create a new edit to make changes. AppEdit edit = edits.insert(app.getApplicationId(), null).execute(); log(String.format("Created edit with id: %s", edit.getId())); return edit; } catch (GoogleJsonResponseException ex) { throw new RuntimeException(ex.getDetails() != null ? ex.getDetails().getMessage() : ex.getMessage(), ex); } catch (IOException ex) { throw new RuntimeException(ex); } }