Skip to content

Commit

Permalink
feat(subscription-info): catch and log api errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stfsy committed Oct 12, 2022
1 parent c845af3 commit 8dcc0f0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/subscription-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,16 @@ class SubscriptionInfo {
throw new Error(SubscriptionInfo.ERROR_SUBSCRIPTION_ALREADY_CANCELLED)
}

// cancel
const statusArray = statusByPlanId[subscriptionPlanId]
const subscriptionId = statusArray.at(0).subscription_id
const cancelled = await this._api.cancelSubscription({ subscription_id: subscriptionId })

return cancelled !== false && cancelled !== 'false'
try {
// cancel
const statusArray = statusByPlanId[subscriptionPlanId]
const subscriptionId = statusArray.at(0).subscription_id
const cancelled = await this._api.cancelSubscription({ subscription_id: subscriptionId })
return cancelled !== false && cancelled !== 'false'
} catch (e) {
console.error(`Failed to cancel subscription because of: ${e}`)
}
return false
}

/**
Expand Down

0 comments on commit 8dcc0f0

Please sign in to comment.