2323
2424import Foundation
2525
26- public enum CheckoutErrorCode : String , Codable {
27- case invalidPayload = " INVALID_PAYLOAD "
28- case invalidSignature = " INVALID_SIGNATURE "
29- case notAuthorized = " NOT_AUTHORIZED "
30- case payloadExpired = " PAYLOAD_EXPIRED "
31- case customerAccountRequired = " CUSTOMER_ACCOUNT_REQUIRED "
32- case storefrontPasswordRequired = " STOREFRONT_PASSWORD_REQUIRED "
33- case cartCompleted = " CART_COMPLETED "
34- case invalidCart = " INVALID_CART "
35- case killswitchEnabled = " KILLSWITCH_ENABLED "
36- case unrecoverableFailure = " UNRECOVERABLE_FAILURE "
37- case policyViolation = " POLICY_VIOLATION "
38- case vaultedPaymentError = " VAULTED_PAYMENT_ERROR "
39- case checkoutLiquidNotMigrated = " CHECKOUT_LIQUID_NOT_MIGRATED "
40- }
41-
42- public enum CheckoutUnavailable {
43- case clientError( code: CheckoutErrorCode )
44- case httpError( statusCode: Int )
45- }
46-
47- /// A type representing Shopify Checkout specific errors.
48- /// "recoverable" indicates that though the request has failed, it should be retried in a fallback browser experience.
49- public enum CheckoutError : Swift . Error {
26+ /// `CheckoutError` represents scenarios where Shopify Checkout may error
27+ ///
28+ /// Each error relates to a different portion of Web Shopify Checkout, except `.sdk` which is an internal swift error
29+ /// When the error is not `.sdk` it is useful to first confirm where the issue exists in your Storefront
30+ /// within a browser, to exclude Checkout Kit from the investigation
31+ ///
32+ /// Every event has a "recoverable" property that indicates this error may be recoverable when retried in a fallback browser experience
33+ /// This may have a degraded experience, implement CheckoutDelegate.shouldRecoverFromError to opt out
34+ public enum CheckoutError : Error {
5035 /// Issued when an internal error within Shopify Checkout SDK
5136 /// In event of an sdkError you could use the stacktrace to inform you of how to proceed,
52- /// if the issue persists, it is recommended to open a bug report in http://github.com/Shopify/checkout-sheet-kit-swift
53- case sdk( underlying: Swift . Error , recoverable: Bool = true )
37+ /// if the issue persists, it is recommended to open a bug report in:
38+ /// http://github.com/Shopify/checkout-sheet-kit-swift/issues
39+ case sdk( underlying: Error , recoverable: Bool = true )
5440
5541 /// Issued when the storefront configuration has caused an error.
56- /// Note that the Checkout Sheet Kit only supports stores migrated for extensibility.
57- case misconfiguration( message: String , code: CheckoutErrorCode , recoverable: Bool = false )
42+ case misconfiguration( message: String , code: ErrorCode , recoverable: Bool = false )
5843
5944 /// Issued when checkout has encountered a unrecoverable error (for example server side error)
60- /// if the issue persists, it is recommended to open a bug report in http://github.com/Shopify/checkout-sheet-kit-swift
45+ /// if the issue persists, it is recommended to open a bug report:
46+ /// http://github.com/Shopify/checkout-sheet-kit-swift/issues
6147 case unavailable( message: String , code: CheckoutUnavailable , recoverable: Bool )
6248
6349 /// Issued when checkout is no longer available and will no longer be available with the checkout url supplied.
6450 /// 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
6551 /// In event of checkoutExpired, a new checkout url will need to be generated
66- case expired( message: String , code: CheckoutErrorCode , recoverable: Bool = false )
52+ case expired( message: String , code: ErrorCode , recoverable: Bool = false )
6753
6854 public var isRecoverable : Bool {
6955 switch self {
@@ -74,15 +60,32 @@ public enum CheckoutError: Swift.Error {
7460 return recoverable
7561 }
7662 }
77- }
7863
79- public struct CheckoutErrorEvent : CheckoutNotification {
80- public static let method = " checkout.error "
81- public let code : CheckoutErrorCode
82- public let message : String
64+ public enum ErrorCode : String , Codable {
65+ /// misconfiguration: recoverable:false
66+ case payloadExpired = " PAYLOAD_EXPIRED "
67+ case invalidPayload = " INVALID_PAYLOAD "
68+ case invalidSignature = " INVALID_SIGNATURE "
69+ case notAuthorized = " NOT_AUTHORIZED "
70+ case customerAccountRequired = " CUSTOMER_ACCOUNT_REQUIRED "
71+ case storefrontPasswordRequired = " STOREFRONT_PASSWORD_REQUIRED "
72+
73+ /// unavailable: recoverable:true
74+ case killswitchEnabled = " KILLSWITCH_ENABLED "
75+ case unrecoverableFailure = " UNRECOVERABLE_FAILURE "
76+ case policyViolation = " POLICY_VIOLATION "
77+ case vaultedPaymentError = " VAULTED_PAYMENT_ERROR "
78+
79+ /// expired: recoverable:false
80+ case cartCompleted = " CART_COMPLETED "
81+ case invalidCart = " INVALID_CART "
82+
83+ /// deprecated?
84+ case checkoutLiquidNotMigrated = " CHECKOUT_LIQUID_NOT_MIGRATED "
85+ }
8386
84- public init ( code : CheckoutErrorCode , message : String ) {
85- self . code = code
86- self . message = message
87+ public enum CheckoutUnavailable {
88+ case clientError ( code: ErrorCode )
89+ case httpError ( statusCode : Int )
8790 }
8891}
0 commit comments