Skip to content
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

Show Stripe error message if error contains Stripe error #960

Merged
merged 3 commits into from
Nov 26, 2018

Conversation

OtterleyW
Copy link
Contributor

No description provided.

return errorAPIErrors(error).reduce((messages, apiError) => {
const isPaymentFailedError =
apiError.status === 402 && apiError.code === ERROR_CODE_PAYMENT_FAILED;
let hasMessage = apiError && apiError.meta && apiError.meta.stripeMessage;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use let since there's no need to update the variable inside its lifespan (i.e. this function block).

apiError.status === 402 && apiError.code === ERROR_CODE_PAYMENT_FAILED;
let hasMessage = apiError && apiError.meta && apiError.meta.stripeMessage;

return isPaymentFailedError && hasMessage ? [...messages, hasMessage] : messages;
Copy link
Contributor

@Gnito Gnito Nov 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be written as:

const hasStripeError = apiError && apiError.meta && apiError.meta.stripeMessage;
const stripeMessageMaybe = isPaymentFailedError && hasStripeError
  ? [apiError.meta.stripeMessage]
  : [];
return [...messages, ...stripeMessageMaybe];

(And probably isPaymentFailedError is redundant check.)

* Check if the given API error (from `sdk.transaction.initiate()`) is
* due to other error in Stripe.
*/
export const isTransactionInitiateStripeError = error => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not returning any boolean, the name should be something else.
How about transactionInitiateOrderStripeErrors or transactionInitiateStripeErrors?

Copy link
Contributor

@Gnito Gnito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small changes.

@OtterleyW OtterleyW force-pushed the fix-initial-order-error-bug branch 3 times, most recently from a2fea58 to 9892e2f Compare November 23, 2018 07:29
@@ -15,7 +15,9 @@ import {
isTransactionInitiateAmountTooLowError,
isTransactionInitiateListingNotFoundError,
isTransactionInitiateMissingStripeAccountError,
transactionInitiateOrderStripeErrors,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved to the end of this list. (This just looks funny in the middle of isTransaction... helper functions.

Copy link
Contributor

@Gnito Gnito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One extra small change.

@OtterleyW OtterleyW merged commit f485a5e into master Nov 26, 2018
@OtterleyW OtterleyW deleted the fix-initial-order-error-bug branch November 26, 2018 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants