Skip to content

Commit

Permalink
Add isRecoverable property to CheckoutError
Browse files Browse the repository at this point in the history
  • Loading branch information
markmur committed Apr 22, 2024
1 parent 4ce9bb3 commit ebad670
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ extension CartViewController: CheckoutDelegate {
}

func shouldRecoverFromError(error: CheckoutError) -> Bool {
return true
return error.isRecoverable
}

func checkoutDidFail(error: ShopifyCheckoutSheetKit.CheckoutError) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ShopifyCheckoutSheetKit/CheckoutDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extension CheckoutDelegate {
}

public func shouldRecoverFromError(error: CheckoutError) -> Bool {
return true
return error.isRecoverable
}

private func handleUrl(_ url: URL) {
Expand Down
11 changes: 11 additions & 0 deletions Sources/ShopifyCheckoutSheetKit/CheckoutError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ public enum CheckoutError: Swift.Error {
/// This may happen when the user has paused on checkout for a long period (hours) and then attempted to proceed again with the same checkout url
/// In event of checkoutExpired, a new checkout url will need to be generated
case checkoutExpired(message: String, code: CheckoutErrorCode, recoverable: Bool = false)

public var isRecoverable: Bool {
switch self {
case .authenticationError(_, _, let recoverable),
.checkoutExpired(_, _, let recoverable),
.checkoutUnavailable(_, _, let recoverable),
.configurationError(_, _, let recoverable),
.sdkError(_, let recoverable):
return recoverable
}
}
}

internal enum CheckoutErrorGroup: String, Codable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,6 @@ extension CheckoutWebViewController: CheckoutWebViewDelegate {
}

private func isErrorRecoverable(error: CheckoutError) -> Bool {
switch error {
case .authenticationError(_, _, let recoverable),
.checkoutExpired(_, _, let recoverable),
.checkoutUnavailable(_, _, let recoverable),
.configurationError(_, _, let recoverable),
.sdkError(_, let recoverable):
return recoverable
}
return error.isRecoverable
}
}

0 comments on commit ebad670

Please sign in to comment.