From 95c5b82e3d0403a6667bb9c071025399d0af57de Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 20 Jul 2023 18:51:44 -0300 Subject: [PATCH 1/6] Comprobe if the request was successfully --- src/api/api.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/api/api.js b/src/api/api.js index 4fe2ec523..2b348eb80 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -519,11 +519,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; } From 9fcc82436cc42397d7bb184d17f416f6e38afafc Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 20 Jul 2023 18:54:48 -0300 Subject: [PATCH 2/6] Change err.error message --- src/components/Settings/Subscribe/Subscribe.container.js | 2 +- .../SubscriptionProvider/SubscriptionProvider.actions.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Settings/Subscribe/Subscribe.container.js b/src/components/Settings/Subscribe/Subscribe.container.js index bceda3796..a626b6d9d 100644 --- a/src/components/Settings/Subscribe/Subscribe.container.js +++ b/src/components/Settings/Subscribe/Subscribe.container.js @@ -251,7 +251,7 @@ export class SubscribeContainer extends PureComponent { }); } } catch (err) { - if (err.response?.data.error === 'subscriber not found') { + if (err.error === 'Subscriber was not found.') { // check if current subscriber already bought in this device if (localReceipts.length) { this.handleError({ diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js index f4c0e5c86..4a490264d 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js @@ -142,7 +142,7 @@ export function updateIsSubscribed(requestOrigin = 'unkwnown') { isSubscribed = false; status = NOT_SUBSCRIBED; let ownedProduct = ''; - if (err.response?.data.error === 'subscriber not found') { + if (err.error === 'Subscriber was not found.') { dispatch( updateSubscription({ ownedProduct, From e8af314bd373dd52b7b46143a56fe19103c3dfb4 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 31 Jul 2023 18:21:25 -0300 Subject: [PATCH 3/6] Revert change on catch --- src/components/Settings/Subscribe/Subscribe.container.js | 2 +- .../SubscriptionProvider/SubscriptionProvider.actions.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Settings/Subscribe/Subscribe.container.js b/src/components/Settings/Subscribe/Subscribe.container.js index a626b6d9d..b25249944 100644 --- a/src/components/Settings/Subscribe/Subscribe.container.js +++ b/src/components/Settings/Subscribe/Subscribe.container.js @@ -251,7 +251,7 @@ export class SubscribeContainer extends PureComponent { }); } } catch (err) { - if (err.error === 'Subscriber was not found.') { + if (err.error === 'subscriber not found') { // check if current subscriber already bought in this device if (localReceipts.length) { this.handleError({ diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js index 4a490264d..52d95dbf8 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js @@ -138,11 +138,11 @@ export function updateIsSubscribed(requestOrigin = 'unkwnown') { ); } } catch (err) { - console.error(err.message); + console.error(err.message + '.', err.error); isSubscribed = false; status = NOT_SUBSCRIBED; let ownedProduct = ''; - if (err.error === 'Subscriber was not found.') { + if (err.error === 'subscriber not found') { dispatch( updateSubscription({ ownedProduct, From 41c572b75ee19a7d0cd6fbbf547e917b0b1ed9fa Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 31 Jul 2023 20:16:17 -0300 Subject: [PATCH 4/6] Support old getSub behaviour --- src/components/Settings/Subscribe/Subscribe.container.js | 5 ++++- .../SubscriptionProvider/SubscriptionProvider.actions.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/Settings/Subscribe/Subscribe.container.js b/src/components/Settings/Subscribe/Subscribe.container.js index b25249944..8b3705656 100644 --- a/src/components/Settings/Subscribe/Subscribe.container.js +++ b/src/components/Settings/Subscribe/Subscribe.container.js @@ -251,7 +251,10 @@ export class SubscribeContainer extends PureComponent { }); } } catch (err) { - if (err.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 (localReceipts.length) { this.handleError({ diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js index 52d95dbf8..b4d9e2f68 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js @@ -142,7 +142,10 @@ export function updateIsSubscribed(requestOrigin = 'unkwnown') { isSubscribed = false; status = NOT_SUBSCRIBED; let ownedProduct = ''; - if (err.error === 'subscriber not found') { + const isSubscriberNotFound = + (err.response?.data?.error || err.error) === 'subscriber not found'; + + if (isSubscriberNotFound) { dispatch( updateSubscription({ ownedProduct, From fbdc3eaa82010837551d0b6a233c823862b3efdd Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 31 Jul 2023 20:17:10 -0300 Subject: [PATCH 5/6] Create error message --- .../SubscriptionProvider/SubscriptionProvider.actions.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js index b4d9e2f68..2b0c8bca2 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js @@ -138,7 +138,13 @@ export function updateIsSubscribed(requestOrigin = 'unkwnown') { ); } } catch (err) { - console.error(err.message + '.', err.error); + const errorMessage = + err.message + + '. ' + + (err.response ? err.response?.data?.message : err.error); + + console.error(errorMessage); + isSubscribed = false; status = NOT_SUBSCRIBED; let ownedProduct = ''; From 4a9532a2f8aa2a70f2371ac8b3aceb86c9614f20 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 16 Aug 2023 14:53:33 -0300 Subject: [PATCH 6/6] Create function to getErrorMessage --- .../SubscriptionProvider.actions.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js index 2b0c8bca2..4a5524848 100644 --- a/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js +++ b/src/providers/SubscriptionProvider/SubscriptionProvider.actions.js @@ -138,12 +138,7 @@ export function updateIsSubscribed(requestOrigin = 'unkwnown') { ); } } catch (err) { - const errorMessage = - err.message + - '. ' + - (err.response ? err.response?.data?.message : err.error); - - console.error(errorMessage); + console.error(getErrorMessage(err)); isSubscribed = false; status = NOT_SUBSCRIBED; @@ -206,6 +201,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() {