Skip to content

Commit

Permalink
Fixed failing members import tests
Browse files Browse the repository at this point in the history
refs TryGhost@05f6faf

- The logic in "Stripe" error detection depended on error's message string matching, which is not a good practice in general. Had fixed it do to exact match on "context" of the error we throw internally and left more extensive comment about why things are implemented the way they are.
  • Loading branch information
naz committed Jul 1, 2020
1 parent 0ee9263 commit d03f674
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/server/api/canary/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ const members = {
});
}

// NOTE: failed to link Stripe customer/plan/subscription
const isStripeLinkingError = error.message && error.message.match(/customer|plan|subscription|Stripe account/g);
// NOTE: failed to link Stripe customer/plan/subscription or have thrown custom Stripe connection error.
// It's a bit ugly doing regex matching to detect errors, but it's the easiest way that works without
// introducing additional logic/data format into current error handling
const isStripeLinkingError = error.message && (error.message.match(/customer|plan|subscription/g) || error.context === i18n.t('errors.api.members.stripeNotConnected.context'));
if (model && isStripeLinkingError) {
if (error.message.indexOf('customer') && error.code === 'resource_missing') {
error.message = `Member not imported. ${error.message}`;
Expand Down

0 comments on commit d03f674

Please sign in to comment.