1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"). 5 * You may not use this file except in compliance with the License. 6 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package software.amazon.awssdk.awscore.internal; 17 18 import static java.util.Collections.unmodifiableSet; 19 20 import java.util.HashSet; 21 import java.util.Set; 22 import software.amazon.awssdk.annotations.SdkInternalApi; 23 24 /** 25 * Contains AWS error codes. 26 */ 27 @SdkInternalApi 28 public final class AwsErrorCode { 29 30 public static final Set<String> RETRYABLE_ERROR_CODES; 31 public static final Set<String> THROTTLING_ERROR_CODES; 32 public static final Set<String> DEFINITE_CLOCK_SKEW_ERROR_CODES; 33 public static final Set<String> POSSIBLE_CLOCK_SKEW_ERROR_CODES; 34 35 static { 36 Set<String> throttlingErrorCodes = new HashSet<>(9); 37 throttlingErrorCodes.add("Throttling"); 38 throttlingErrorCodes.add("ThrottlingException"); 39 throttlingErrorCodes.add("ThrottledException"); 40 throttlingErrorCodes.add("ProvisionedThroughputExceededException"); 41 throttlingErrorCodes.add("SlowDown"); 42 throttlingErrorCodes.add("TooManyRequestsException"); 43 throttlingErrorCodes.add("RequestLimitExceeded"); 44 throttlingErrorCodes.add("BandwidthLimitExceeded"); 45 throttlingErrorCodes.add("RequestThrottled"); 46 throttlingErrorCodes.add("RequestThrottledException"); 47 throttlingErrorCodes.add("EC2ThrottledException"); 48 throttlingErrorCodes.add("TransactionInProgressException"); 49 THROTTLING_ERROR_CODES = unmodifiableSet(throttlingErrorCodes); 50 51 Set<String> definiteClockSkewErrorCodes = new HashSet<>(3); 52 definiteClockSkewErrorCodes.add("RequestTimeTooSkewed"); 53 definiteClockSkewErrorCodes.add("RequestExpired"); 54 definiteClockSkewErrorCodes.add("RequestInTheFuture"); 55 DEFINITE_CLOCK_SKEW_ERROR_CODES = unmodifiableSet(definiteClockSkewErrorCodes); 56 57 Set<String> possibleClockSkewErrorCodes = new HashSet<>(3); 58 possibleClockSkewErrorCodes.add("InvalidSignatureException"); 59 possibleClockSkewErrorCodes.add("SignatureDoesNotMatch"); 60 possibleClockSkewErrorCodes.add("AuthFailure"); 61 POSSIBLE_CLOCK_SKEW_ERROR_CODES = unmodifiableSet(possibleClockSkewErrorCodes); 62 63 Set<String> retryableErrorCodes = new HashSet<>(1); 64 retryableErrorCodes.add("PriorRequestNotComplete"); 65 retryableErrorCodes.add("RequestTimeout"); 66 retryableErrorCodes.add("RequestTimeoutException"); 67 retryableErrorCodes.add("InternalError"); 68 RETRYABLE_ERROR_CODES = unmodifiableSet(retryableErrorCodes); 69 } 70 AwsErrorCode()71 private AwsErrorCode() { 72 } 73 isThrottlingErrorCode(String errorCode)74 public static boolean isThrottlingErrorCode(String errorCode) { 75 return THROTTLING_ERROR_CODES.contains(errorCode); 76 } 77 isDefiniteClockSkewErrorCode(String errorCode)78 public static boolean isDefiniteClockSkewErrorCode(String errorCode) { 79 return DEFINITE_CLOCK_SKEW_ERROR_CODES.contains(errorCode); 80 } 81 isPossibleClockSkewErrorCode(String errorCode)82 public static boolean isPossibleClockSkewErrorCode(String errorCode) { 83 return POSSIBLE_CLOCK_SKEW_ERROR_CODES.contains(errorCode); 84 } 85 isRetryableErrorCode(String errorCode)86 public static boolean isRetryableErrorCode(String errorCode) { 87 return RETRYABLE_ERROR_CODES.contains(errorCode); 88 } 89 } 90