Skip to content

Commit 41f4bbe

Browse files
committed
Do not retry on service unavailable
1 parent fe055f5 commit 41f4bbe

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

Sources/Core/Extensions/ErrorExtensions.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ extension Error {
3131

3232
var isRetryableWithBackoff: Bool {
3333
let isTooManyRequests = statusCode == ResponseStatus.tooManyRequests
34+
let isServiceUnavailable = statusCode == ResponseStatus.serviceUnavailable
3435
let isServerError = ResponseStatus.serverErrorRange.contains(statusCode)
3536

36-
return isTooManyRequests || isServerError
37+
return isTooManyRequests || (isServerError && !isServiceUnavailable)
3738
}
3839

3940
var isRetryable: Bool {

Sources/Core/Models/Error/APIError.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public enum APIError: Swift.Error, Hashable, Sendable {
5757
statusCode == ResponseStatus.tooManyRequests
5858
}
5959

60+
/// Verify if API request failed with "serviceUnavailable" (503) status code.
61+
public var isServiceUnavailable: Bool {
62+
statusCode == ResponseStatus.serviceUnavailable
63+
}
64+
6065
/// Error response that was returned by the API.
6166
public var errorResponse: APIErrorResponse? {
6267
switch self {

Sources/Core/Models/Response/ResponseStatus.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ public struct ResponseStatus: RawRepresentable, Hashable, Comparable, Sendable,
3232
public static let forbidden = ResponseStatus(rawValue: 403)
3333
public static let tooManyRequests = ResponseStatus(rawValue: 429)
3434
public static let serverError = ResponseStatus(rawValue: 500)
35+
public static let serviceUnavailable = ResponseStatus(rawValue: 503)
3536
public static let networkConnectTimeoutError = ResponseStatus(rawValue: 599)
3637
}

Tests/Error/ErrorTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ final class ErrorTests: XCTestCase {
4242
let badRequest = APIError(response: Response(model: Data(), statusCode: 400))
4343
let tooManyRequests = APIError(response: Response(model: Data(), statusCode: 429))
4444
let serverError = APIError(response: Response(model: Data(), statusCode: 500))
45+
let serviceUnavailable = APIError(response: Response(model: Data(), statusCode: 503))
4546
XCTAssert(tooManyRequests.isRetryableWithBackoff)
4647
XCTAssert(serverError.isRetryableWithBackoff)
4748
XCTAssertFalse(badRequest.isRetryableWithBackoff)
49+
XCTAssertFalse(serviceUnavailable.isRetryableWithBackoff)
4850
}
4951

5052
func testDecodeErrorResponse() throws {

0 commit comments

Comments
 (0)