Skip to content

Commit

Permalink
Merge pull request #1551 from RodriSanchez1/fix/refactorGetSubscriber…
Browse files Browse the repository at this point in the history
…NotFound

Fix/refactor get subscriber not found
  • Loading branch information
martinbedouret authored Dec 18, 2023
2 parents e4ce4c0 + 4a9532a commit 0d3c5d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion src/components/Settings/Subscribe/Subscribe.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 14 additions & 2 deletions src/providers/SubscriptionProvider/SubscriptionProvider.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 0d3c5d5

Please sign in to comment.