Skip to content

Commit

Permalink
Catch decode error to avoid disrupting user experience
Browse files Browse the repository at this point in the history
  • Loading branch information
markmur committed Feb 22, 2024
1 parent fad647a commit b0ec795
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 8 additions & 2 deletions Sources/ShopifyCheckoutSheetKit/CheckoutBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO
*/

import WebKit
import os.log

enum BridgeError: Swift.Error {
case invalidBridgeEvent(Swift.Error? = nil)
Expand Down Expand Up @@ -101,8 +102,13 @@ extension CheckoutBridge {
switch name {
case "completed":
let checkoutCompletedEventDecoder = CheckoutCompletedEventDecoder()
let checkoutCompletedEvent = try checkoutCompletedEventDecoder.decode(from: container, using: decoder)
self = .checkoutComplete(event: checkoutCompletedEvent)
do {
let checkoutCompletedEvent = try checkoutCompletedEventDecoder.decode(from: container, using: decoder)
self = .checkoutComplete(event: checkoutCompletedEvent)
} catch {
os_log(.error, "[ShopifyCheckoutSheetKit] Error decoding CheckoutCompletedEvent: %{public}@", error as CVarArg)
self = .checkoutComplete(event: CheckoutCompletedEvent())
}
case "error":
// needs to support .checkoutUnavailable by parsing error payload on body
self = .checkoutExpired
Expand Down
3 changes: 0 additions & 3 deletions Sources/ShopifyCheckoutSheetKit/CheckoutDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public protocol CheckoutDelegate: AnyObject {
}

extension CheckoutDelegate {
/// Deprecated and will be removed in the next major release
public func checkoutDidComplete() {}

public func checkoutDidComplete(event: CheckoutCompletedEvent) {
/// No-op by default
}
Expand Down

0 comments on commit b0ec795

Please sign in to comment.