-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error Refactor Spike #300
Closed
Closed
Error Refactor Spike #300
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Remove MXO * remove Package.resolved file containing incompatible pinstorage version * CHANGELOG entry * Jax feedback and docStrings correction * Remove PatchOrder for MXO, unused files in demo app * Remove more classes used exclusively for MXO
* PayPal remove delgation pattern for completion handler function for checkout * lint error for paypal start * completion and analytics into notify functions * paypal vault completion, unit tests * remove PayPal delegates, references * Card vault to completion, unit tests * Card approve to completion, unit tests * docstrings for approve completion param * wrap paypal functions in async await * async await wrapper for CardClient functions * remove CardDelegate and references * fix error in notifyCheckoutFailure * Make error names and messages payPal caps consistent * changelog entires * Steven PR feedback: typo in Chagelog
* Simplify cancel errors * CHANGELOG for the cancel errors * Steven PR feedback: change back CardClientError.canceled to .threeDSecureCanceled * CHANGELOG update
* http performRequest returns NetworkingClientErrors * CardClient helper function for threeDSCancel, demo app cancel, demo app minor fixes * PayPalClient cancel helper functions and demo app changes * Steven PR feedback: move static helper functions to error enums * Rename CardClientError -> CardError, PayPalWebCheckoutError -> PayPalError * Steven PR feedback: return CoreSDKError in merchant completion handler * CHANGELOG and analytics typo and fix wrong code in graphql error
* v2 migration guide * just cocoapods or SPM * fix typos * minor spacing changes * Update with simplified cancel errors * Steven PR feedback - diff to render green/red * include removal of delegate methods in delete block * update with cardClient threeDSecureCanceled error * change to threeDSecureCanceled in migration steps * add comment highlighting cancellation errors * typo fix * clarify separating cancel cases in errors * revert cancel handling instructions * add changes for cancellation helper methods * fix typo in PayPalError.isCheckoutCanceled * Steven PR feedback
* Changelog: move additive changes from breaking section * remove duplicate line for PayPal cancel errors
Closing this, can be used as reference. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reason for changes
Problem Statement
Our SDK currently returns a single error type,
CoreSDKError
, which records:• Domain: A String indicating the origin of the error (e.g.,
CardClientErrorDomain
,PayPalClientErrorDomain
).• Code: An Int value classifying specific errors.
• Error Description: A string for the error.
This design is similar to
NSError
, which also provides domain, code, and localizedDescription.Each module defines its own enum (e.g.,
CardError
,NetworkingClientError
) with:CoreSDKError
under the hood.For example:
•
CardClient
defines its own errors, including those from 3DS verification.• Errors propagate up from networking layers as
CoreSDKError
with names reflecting their module and level of origin, but merchants must use domain and code checks to handle specific cases.Challenges with the Current Design
Merchants must rely on the domain and code properties to identify specific errors, which can lead to verbose and error-prone code:
To simplify cancellation handling in the beta release, I introduced helper methods like:
While functional, this approach is not intuitive or consistent with Swift’s idiomatic error handling.
Limited Extensibility:
Introducing new modules or errors requires updating CoreSDKError and potentially modifying helper methods, increasing maintenance complexity.
Merchant Experience:
The current design does not align well with how merchants typically handle errors. Instead of looking at centralized domains and codes, merchants prefer to interact with module-specific error types directly.
Proposed Alternatives
• Each module defines its own error type (e.g.,
CardError
,PayPalError
), conforming toError
,LocalizedError
, andEquatable
.• Completion handlers return a general Error type, allowing merchants to switch on module-specific errors:
Advantages:
• Clear and modular error handling.
• Merchants can switch directly on error types without relying on domains and codes.
Disadvantages:
• Merchants must cast errors to module-specific types when needed.
• Use Status enum with possibly
CoreSDKError
:• Completion handlers return
Status
, allowing merchants to handle success, cancellation, and failure in a unified manner:Advantages:
• Simplifies error handling by combining results and statuses.
Disadvantages:
• It may not be a pattern merchants are used to and some flows such as card payment without 3DS don't have cancel path.
• Merchants still need to cast Error for specific cases.
• Adopt a design similar to NSError, where all errors are generic with domain, code, and localizedDescription.
Advantages:
• Familiar to many developers.
• Reduces complexity by avoiding module-specific error types.
Disadvantages:
• Does not leverage Swift’s strong typing.
• Error handling becomes verbose and less intuitive.
Recommendation
I recommend adopting module-specific error types (Alternative 1), similar to Braintree’s approach:
• Each module manages its own errors (
CardError
,PayPalError
,NetworkingErrors
that conform toEquatable
protocol).• Completion handlers return a generic Error type for compatibility.
• Merchants can handle errors using switch statements or type casting.
I think keeping errors as they are is also a viable option as well.
It is a pattern that developers are used to and I understand reason for this implementation.
Cancel separate handling may be not needed by majority of merchants and helper function
should be adequate for merchants if they want to do so. They can also write their own helper
functions to discern the error codes from our internal module specific enum types.
My final thoughts are to release our current v2_beta branch as beta1 and gage merchant feedback for changes.
There are already significant changes from delegation pattern to completion handler and async/await pattern in beta1.
Checklist
Authors