triniwiz / triniwiz/nativescript-plugins
[nativescript-stripe] Better error handling
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 87
- Forks
- 57
- Avg merge
- 1h 36m
- Merged PRs (30d)
- 4
Description
Hi there!
I've been using this plugin for a while, but with a custom patch in order to have a better error handling.
I had an issue in the past on Android where a basic Exception was thrown instead of a StripeException. In this case, calling error.getLocalizedMessage() fails and another exception is thrown.
So I added a _getLocalizedError function, which will test if the error is an instance of StripeException and thus call getLocalizedMessage(). It will also add Stripe's error code and decline code to the error returned.
Here is the function for Android:
_getLocalizedError(error) {
let localizedError
if (error instanceof com.stripe.android.exception.StripeException) {
localizedError = new Error(error.getLocalizedMessage() || error.getMessage());
if (error.stripeError) {
localizedError.code = error.stripeError.code;
localizedError.declineCode = error.stripeError.declineCode;
}
} else {
localizedError = new Error(error.message);
}
return localizedError
}
And the one for iOS:
_getLocalizedError(error, intent) {
const localizedError = new Error(error.localizedDescription);
if (intent?.lastPaymentError) {
localizedError.code = intent.lastPaymentError.code;
localizedError.declineCode = intent.lastPaymentError.declineCode;
}
return localizedError
}
Then I replaced all these calls by my function:
- cb(new Error(error.getMessage() || error.getLocalizedMessage()), null);
+ cb(this._getLocalizedError(error), null);
I was wondering if you were interested to add this to the plugin. I would be glad to make a PR in that case :)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named. Start by locating the nativescript-stripe Android and iOS error callback sites represented by the supplied diff, then compare their current error handling with the proposed functions; done means localized errors no longer trigger a secondary exception and Stripe code and decline code are preserved when available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, ios, javascript
- Domain
- mobile-dev, payments
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100