Skip to content

Commit

Permalink
favour flattened error hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
cianbuckley committed Oct 31, 2023
1 parent 178a52c commit 22935ac
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ extension MyViewController: ShopifyCheckoutDelegate {

/// Issued when the provided checkout URL results in an error related to shop being on checkout.liquid.
/// The SDK only supports stores migrated for extensibility.
case sdkError(underlying: CheckoutLiquidError.unmigratedCheckout)
case checkoutLiquidNotMigrated(message: String)

/// Unavailable error: checkout cannot be initiated or completed, e.g. due to network or server-side error
/// The provided message describes the error and may be logged and presented to the buyer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,14 @@ extension CartViewController: CheckoutDelegate {

func checkoutDidFail(error: ShopifyCheckout.CheckoutError) {
switch error {
case .sdkError(let underlying): print(#function, underlying)
case .sdkError(let underlying):
print(#function, underlying)
forceCloseCheckout("Checkout Unavailable")
case .checkoutExpired(let message): forceCloseCheckout(message)
case .checkoutUnavailable(let message): forceCloseCheckout(message)
case .checkoutLiquidNotMigrated(let message):
print(#function, message)
forceCloseCheckout("Checkout Unavailable")
}
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/ShopifyCheckout/CheckoutDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ extension CheckoutDelegate {
handleUrl(url)
}

public func checkoutDidFail(error: CheckoutError) throws {
throw error
}

private func handleUrl(_ url: URL) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
Expand Down
9 changes: 4 additions & 5 deletions Sources/ShopifyCheckout/CheckoutError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public enum CheckoutError: Swift.Error {
/// if the issue persists, it is recommended to open a bug report in http://github.com/Shopify/mobile-checkout-sdk-ios
case sdkError(underlying: Swift.Error)

/// Issued when the provided checkout URL results in an error related to shop being on checkout.liquid.
/// The SDK only supports stores migrated for extensibility.
case checkoutLiquidNotMigrated(message: String)

/// Issued when checkout has encountered a unrecoverable error (for example server side error)
/// if the issue persists, it is recommended to open a bug report in http://github.com/Shopify/mobile-checkout-sdk-ios
case checkoutUnavailable(message: String)
Expand All @@ -38,8 +42,3 @@ public enum CheckoutError: Swift.Error {
case checkoutExpired(message: String)
}

Check failure on line 44 in Sources/ShopifyCheckout/CheckoutError.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Newline Violation: Files should have a single trailing newline (trailing_newline)
public enum CheckoutLiquidError: Swift.Error {
/// Issued when the provided checkout URL results in an error related to shop being on checkout.liquid.
/// The SDK only supports stores migrated for extensibility.
case unmigratedCheckoutError(message: String)
}
2 changes: 1 addition & 1 deletion Sources/ShopifyCheckout/CheckoutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ extension CheckoutView: WKNavigationDelegate {
case 410:
viewDelegate?.checkoutViewDidFailWithError(error: .checkoutExpired(message: "Checkout has expired"))
case 404:
viewDelegate?.checkoutViewDidFailWithError(error: .sdkError(underlying: CheckoutLiquidError.unmigratedCheckoutError(message: "The checkout url provided has resulted in an error. The store is still using checkout.liquid, whereas the checkout SDK only supports checkout with extensibility.")))
viewDelegate?.checkoutViewDidFailWithError(error: .checkoutLiquidNotMigrated(message: "The checkout url provided has resulted in an error. The store is still using checkout.liquid, whereas the checkout SDK only supports checkout with extensibility."))
case 500:
viewDelegate?.checkoutViewDidFailWithError(error: .checkoutUnavailable(message: "Checkout unavailable due to error"))
default:
Expand Down

0 comments on commit 22935ac

Please sign in to comment.