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

The following examples show how to use com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo#getReason() . 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: ApiErrorExtractor.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if a given Throwable is caused by a rate limit being applied. Recursively checks
 * getCause() if outer exception isn't an instance of the correct class.
 *
 * @param e The Throwable to check.
 * @return True if the Throwable is a result of rate limiting being applied.
 */
public boolean rateLimited(IOException e) {
  ErrorInfo errorInfo = getErrorInfo(e);
  if (errorInfo != null) {
    String domain = errorInfo.getDomain();
    boolean isRateLimitedOrGlobalDomain =
        USAGE_LIMITS_DOMAIN.equals(domain) || GLOBAL_DOMAIN.equals(domain);
    String reason = errorInfo.getReason();
    boolean isRateLimitedReason =
        RATE_LIMITED_REASON.equals(reason) || USER_RATE_LIMITED_REASON.equals(reason);
    return isRateLimitedOrGlobalDomain && isRateLimitedReason;
  }
  return false;
}
 
Example 2
Source File: ApiErrorExtractor.java    From hadoop-connectors with Apache License 2.0 4 votes vote down vote up
/**
 * Determines if the exception is a non-recoverable access denied code (such as account closed or
 * marked for deletion).
 */
public boolean accessDeniedNonRecoverable(IOException e) {
  ErrorInfo errorInfo = getErrorInfo(e);
  String reason = errorInfo != null ? errorInfo.getReason() : null;
  return ACCOUNT_DISABLED_REASON.equals(reason) || ACCESS_NOT_CONFIGURED_REASON.equals(reason);
}