-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
error_inspector.rb
144 lines (124 loc) · 4.46 KB
/
error_inspector.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# frozen_string_literal: true
module Aws
module Plugins
module Retries
# @api private
# This class will be obsolete when APIs contain modeled exceptions
class ErrorInspector
EXPIRED_CREDS = Set.new(
[
'InvalidClientTokenId', # query services
'UnrecognizedClientException', # json services
'InvalidAccessKeyId', # s3
'AuthFailure', # ec2
'InvalidIdentityToken', # sts
'ExpiredToken' # route53
]
)
THROTTLING_ERRORS = Set.new(
[
'Throttling', # query services
'ThrottlingException', # json services
'ThrottledException', # sns
'RequestThrottled', # sqs
'RequestThrottledException', # generic service
'ProvisionedThroughputExceededException', # dynamodb
'TransactionInProgressException', # dynamodb
'RequestLimitExceeded', # ec2
'BandwidthLimitExceeded', # cloud search
'LimitExceededException', # kinesis
'TooManyRequestsException', # batch
'PriorRequestNotComplete', # route53
'SlowDown', # s3
'EC2ThrottledException' # ec2
]
)
CHECKSUM_ERRORS = Set.new(
[
'CRC32CheckFailed' # dynamodb
]
)
NETWORKING_ERRORS = Set.new(
[
'RequestTimeout', # s3
'RequestTimeoutException', # glacier
'IDPCommunicationError' # sts
]
)
# See: https://github.com/aws/aws-sdk-net/blob/5810dfe401e0eac2e59d02276d4b479224b4538e/sdk/src/Core/Amazon.Runtime/Pipeline/RetryHandler/RetryPolicy.cs#L78
CLOCK_SKEW_ERRORS = Set.new(
[
'RequestTimeTooSkewed',
'RequestExpired',
'InvalidSignatureException',
'SignatureDoesNotMatch',
'AuthFailure',
'RequestInTheFuture'
]
)
def initialize(error, http_status_code)
@error = error
@name = extract_name(@error)
@http_status_code = http_status_code
end
def expired_credentials?
!!(EXPIRED_CREDS.include?(@name) || @name.match(/expired/i))
end
def throttling_error?
!!(THROTTLING_ERRORS.include?(@name) ||
@name.match(/throttl/i) ||
@http_status_code == 429) ||
modeled_throttling?
end
def checksum?
CHECKSUM_ERRORS.include?(@name) || @error.is_a?(Errors::ChecksumError)
end
def networking?
@error.is_a?(Seahorse::Client::NetworkingError) ||
@error.is_a?(Errors::NoSuchEndpointError) ||
NETWORKING_ERRORS.include?(@name)
end
def server?
(500..599).cover?(@http_status_code)
end
def endpoint_discovery?(context)
return false unless context.operation.endpoint_discovery
@http_status_code == 421 ||
@name == 'InvalidEndpointException' ||
@error.is_a?(Errors::EndpointDiscoveryError)
end
def modeled_retryable?
@error.is_a?(Errors::ServiceError) && @error.retryable?
end
def modeled_throttling?
@error.is_a?(Errors::ServiceError) && @error.throttling?
end
def clock_skew?(context)
CLOCK_SKEW_ERRORS.include?(@name) &&
context.config.clock_skew.clock_skewed?(context)
end
def retryable?(context)
server? ||
modeled_retryable? ||
throttling_error? ||
networking? ||
checksum? ||
endpoint_discovery?(context) ||
(expired_credentials? && refreshable_credentials?(context)) ||
clock_skew?(context)
end
private
def refreshable_credentials?(context)
context.config.credentials.respond_to?(:refresh!)
end
def extract_name(error)
if error.is_a?(Errors::ServiceError)
error.class.code || error.class.name.to_s
else
error.class.name.to_s
end
end
end
end
end
end