diff --git a/src/api/api.js b/src/api/api.js index 503ecc4ef..b0227d485 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -518,11 +518,17 @@ class API { } const headers = { Authorization: `Bearer ${authToken}`, - requestOrigin + requestOrigin, + newVersion: 'true' }; const { data } = await this.axiosInstance.get(`/subscriber/${userId}`, { headers }); + + if (data && !data.success) { + throw data; + } + return data; } diff --git a/src/components/Settings/Subscribe/Subscribe.container.js b/src/components/Settings/Subscribe/Subscribe.container.js index 889bf00a7..fcbef583a 100644 --- a/src/components/Settings/Subscribe/Subscribe.container.js +++ b/src/components/Settings/Subscribe/Subscribe.container.js @@ -284,7 +284,10 @@ export class SubscribeContainer extends PureComponent { }); } } catch (err) { - if (err.response?.data.error === 'subscriber not found') { + const isSubscriberNotFound = + (err.response?.data?.error || err.error) === 'subscriber not found'; + + if (isSubscriberNotFound) { // check if current subscriber already bought in this device if (isAndroid()) { if (localReceipts.length) { diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js index a4677df31..b26c254b0 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js @@ -215,11 +215,15 @@ export function updateIsSubscribed(requestOrigin = 'unkwnown') { ); } } catch (err) { - console.error(err.message); + console.error(getErrorMessage(err)); + isSubscribed = false; status = NOT_SUBSCRIBED; let ownedProduct = ''; - if (err.response?.data.error === 'subscriber not found') { + const isSubscriberNotFound = + (err.response?.data?.error || err.error) === 'subscriber not found'; + + if (isSubscriberNotFound) { dispatch( updateSubscription({ ownedProduct, @@ -274,6 +278,14 @@ export function updateIsSubscribed(requestOrigin = 'unkwnown') { } return isSubscribed; }; + + function getErrorMessage(err) { + return ( + err.message + + '. ' + + (err.response ? err.response?.data?.message : err.error) + ); + } } export function updatePlans() {