Refine search
if (e.getStatusCode() == 404) { U.warn(log, "Bucket doesn't exist, will create it [bucketName=" + bucketName + "]");
private static String message(IOException exception) { if (exception instanceof GoogleJsonResponseException) { GoogleJsonError details = ((GoogleJsonResponseException) exception).getDetails(); if (details != null) { return details.getMessage(); } } return exception.getMessage(); } }
if (exception instanceof HttpResponseException) { if (exception instanceof GoogleJsonResponseException) { GoogleJsonError jsonError = ((GoogleJsonResponseException) exception).getDetails(); if (jsonError != null) { BaseServiceException.Error error = new BaseServiceException.Error(jsonError.getCode(), reason(jsonError)); code = error.getCode(); reason = error.getReason(); retryable = error.isRetryable(idempotent, retryableErrors); if (reason != null) { GoogleJsonError.ErrorInfo errorInfo = jsonError.getErrors().get(0); location = errorInfo.getLocation(); debugInfo = (String) errorInfo.get("debugInfo"); code = ((GoogleJsonResponseException) exception).getStatusCode(); retryable = BaseServiceException.isRetryable(code, null, idempotent, retryableErrors);
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; } }
boolean tryAgain = false; switch (gjre.getStatusCode()) { case 400 : LOGGER.warn("Bad Request : {}", gjre); break; case 403 : LOGGER.warn("Possible rate limit exception. Retrying. : {}", gjre.getMessage()); backOff.backOff(); tryAgain = true;
private static String resolveJsonResponseToMessage(GoogleJsonResponseException reason) { switch (reason.getStatusCode()) { case 403: return StackdriverDebuggerBundle.message("clouddebug.debug.targets.accessdenied"); default: return StackdriverDebuggerBundle.getString( "clouddebug.debug.targets.error", reason.getDetails().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; }
/** * Static builder to construct a {@code GoogleApiException} from a {@link * GoogleJsonResponseException} * * @param exception a GoogleJsonResponseException that was thrown by a Google API call */ public static GoogleApiException from(GoogleJsonResponseException exception) { String message = exception.getDetails() != null ? exception.getDetails().getMessage() : exception.getMessage(); return new GoogleApiException(message, exception, exception.getStatusCode()); }
public static boolean isPermissionDenied(GoogleJsonResponseException e) { return e.getStatusCode() == 403 && Optional.ofNullable(e.getDetails()) .map(GcpUtil::isPermissionDenied) .orElse(false); }
public List<SimpleResult> getResults(String query, int numresults) { List<SimpleResult> urls = new ArrayList<>(); search.setQ(query); search.setMaxResults((long) numresults); SearchListResponse searchResponse; try { searchResponse = search.execute(); List<SearchResult> searchResultList = searchResponse.getItems(); searchResultList.forEach((sr) -> urls.add(new SimpleResult(sr.getId().getVideoId(), sr.getSnippet().getTitle()))); } catch (GoogleJsonResponseException e) { if (e.getMessage().contains("quotaExceeded") || e.getMessage().contains("keyInvalid")) { if (setupNextKey()) { return getResults(query, numresults); } } else { Launcher.logToDiscord(e, "youtube-search-error", "<--", "code", e.getDetails().getCode(), "message", e.getDetails().getMessage()); } } catch (IOException ex) { DiscordBot.LOGGER.error("YTSearch failure: " + ex.toString()); return null; } return urls; }
@Override public BackgroundException map(final IOException failure) { final StringBuilder buffer = new StringBuilder(); if(failure instanceof GoogleJsonResponseException) { final GoogleJsonResponseException error = (GoogleJsonResponseException) failure; this.append(buffer, error.getDetails().getMessage()); switch(error.getDetails().getCode()) { case HttpStatus.SC_FORBIDDEN: final List<GoogleJsonError.ErrorInfo> errors = error.getDetails().getErrors(); for(GoogleJsonError.ErrorInfo info : errors) { if("usageLimits".equals(info.getDomain())) { return new RetriableAccessDeniedException(buffer.toString(), Duration.ofSeconds(5), failure); } } break; } } if(failure instanceof HttpResponseException) { final HttpResponseException response = (HttpResponseException) failure; this.append(buffer, response.getStatusMessage()); return new HttpResponseExceptionMappingService().map(new org.apache.http.client .HttpResponseException(response.getStatusCode(), buffer.toString())); } return super.map(failure); } }
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); } }
try { // Make your Google API call } catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); // Print out the message and errors }
private GoogleJsonError getGoogleJsonError(Exception e) { if (e instanceof GoogleJsonResponseException) { return ((GoogleJsonResponseException) e).getDetails(); } boolean retryableException = (e instanceof SSLHandshakeException || e instanceof SocketTimeoutException); if (retryableException) { logger.log(Level.WARNING, "Retrying request failed with exception:", e); } // Using retryable 504 Gateway Timeout error code. int errorCode = retryableException ? 504 : 0; GoogleJsonError error = new GoogleJsonError(); error.setMessage(e.getMessage()); error.setCode(errorCode); return error; } }
List<ErrorInfo> errors = e.getDetails().getErrors(); for (ErrorInfo error : errors) { if (error.getReason().equals("noAdSenseAccount")) {
} catch (GoogleJsonResponseException e) { LOG.warning("Failed to create timeline subscription. Might be running on " + "localhost. Details:" + e.getDetails().toPrettyString());
public <T> void execute(StorageRequest<T> req, JsonBatchCallback<T> callback) throws IOException { try { T result = req.execute(); callback.onSuccess(result, req.getLastResponseHeaders()); } catch (IOException e) { GoogleJsonResponseException je = ApiErrorExtractor.getJsonResponseExceptionOrNull(e); if (je == null) { throw e; } callback.onFailure(je.getDetails(), je.getHeaders()); } }
} catch (GoogleJsonResponseException e) { System.err.println(e.getMessage()); } catch (HttpResponseException e) {
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { errorInfo.setFactory(jsonFactory); GoogleJsonError jsonError = new GoogleJsonError(); jsonError.setCode(status); jsonError.setErrors(Collections.singletonList(errorInfo)); request.setThrowExceptionOnExecuteError(false); HttpResponse response = request.execute(); return GoogleJsonResponseException.from(jsonFactory, response);
@Override protected GoogleJsonResponseException newExceptionOnError(HttpResponse response) { return GoogleJsonResponseException.from(getAbstractGoogleClient().getJsonFactory(), response); }