Skip to content

Commit

Permalink
Merge pull request #138 from amzn/429retries
Browse files Browse the repository at this point in the history
Add 429 errors as retryable client errors
  • Loading branch information
Janujan authored Jul 12, 2024
2 parents 0ac5bfe + 5103611 commit a6f386f
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public extension HTTPOperationsClient {
} catch let error as HTTPClientError {
// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand All @@ -145,7 +145,7 @@ public extension HTTPOperationsClient {
case .clientError:
// never retry
shouldRetryOnError = false
case .serverError:
case .serverError, .clientRetryableError:
shouldRetryOnError = retryOnError(error)
}
let logger = invocationContext.reporting.logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public extension HTTPOperationsClient {
} catch let error as HTTPClientError {
// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand All @@ -146,7 +146,7 @@ public extension HTTPOperationsClient {
case .clientError:
// never retry
shouldRetryOnError = false
case .serverError:
case .serverError, .clientRetryableError:
shouldRetryOnError = retryOnError(error)
}
let logger = invocationContext.reporting.logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public extension HTTPOperationsClient {
if let typedError = error as? HTTPClientError {
// report failure metric
switch typedError.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public extension HTTPOperationsClient {
if let typedError = error as? HTTPClientError {
// report failure metric
switch typedError.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch innerError.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public extension HTTPOperationsClient {
if let typedError = error as? HTTPClientError {
// report failure metric
switch typedError.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public extension HTTPOperationsClient {
if let typedError = error as? HTTPClientError {
// report failure metric
switch typedError.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
7 changes: 6 additions & 1 deletion Sources/SmokeHTTPClient/HttpClientError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public struct HTTPClientError: Error {

public enum Category {
case clientError
case clientRetryableError
case serverError
}

Expand All @@ -32,7 +33,11 @@ public struct HTTPClientError: Error {
public var category: Category {
switch responseCode {
case 400...499:
return .clientError
if(responseCode == 429) {
return .clientRetryableError
} else {
return .clientError
}
default:
return .serverError
}
Expand Down

0 comments on commit a6f386f

Please sign in to comment.