diff options
author | Sebastian <sebasjm@gmail.com> | 2023-05-12 11:23:38 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-05-12 11:23:38 -0300 |
commit | da93d2ba7eca78359490d5e35b8c70b2bcaf4072 (patch) | |
tree | 50dbf05271ae43546665d58ab00153fa5e4fd591 /packages | |
parent | f7481ba1d8e4575bc534025dbe99f57c6b50102e (diff) |
fix getting wrong error message after 401 response in merchant backoffice
Diffstat (limited to 'packages')
12 files changed, 39 insertions, 35 deletions
diff --git a/packages/demobank-ui/src/hooks/access.ts b/packages/demobank-ui/src/hooks/access.ts index 0d4a8bab8..b8b6ab899 100644 --- a/packages/demobank-ui/src/hooks/access.ts +++ b/packages/demobank-ui/src/hooks/access.ts @@ -209,7 +209,7 @@ export function useAccountDetails( }); return clone; } - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -239,7 +239,7 @@ export function useWithdrawalDetails( // if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -269,7 +269,7 @@ export function useTransactionDetails( // if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -307,7 +307,7 @@ export function usePublicAccounts( if (afterData) setLastAfter(afterData); }, [afterData]); - if (afterError) return afterError.info; + if (afterError) return afterError.cause; // if the query returns less that we ask, then we have reach the end or beginning const isReachingEnd = diff --git a/packages/demobank-ui/src/hooks/backend.ts b/packages/demobank-ui/src/hooks/backend.ts index df85252f7..83df53a1a 100644 --- a/packages/demobank-ui/src/hooks/backend.ts +++ b/packages/demobank-ui/src/hooks/backend.ts @@ -347,7 +347,9 @@ export function useBackendConfig(): HttpResponse< useEffect(() => { request<Type>(`/config`) .then((data) => setResult(data)) - .catch((error) => setResult(error)); + .catch((error: RequestError<SandboxBackend.SandboxError>) => + setResult(error.cause), + ); }, [request]); return result; diff --git a/packages/demobank-ui/src/hooks/circuit.ts b/packages/demobank-ui/src/hooks/circuit.ts index 3ed8ad358..06557b77f 100644 --- a/packages/demobank-ui/src/hooks/circuit.ts +++ b/packages/demobank-ui/src/hooks/circuit.ts @@ -379,7 +379,7 @@ export function useBusinessAccountDetails( }); if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -406,7 +406,7 @@ export function useRatiosAndFeeConfig(): HttpResponse< }); if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -479,7 +479,7 @@ export function useBusinessAccounts( return { ok: true as const, data: { customers }, ...pagination }; }, [afterData?.data]); - if (afterError) return afterError.info; + if (afterError) return afterError.cause; if (afterData) { return result; } @@ -565,6 +565,6 @@ export function useCashoutDetails( }); if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } diff --git a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx index 9c50dfe43..cb4abdd40 100644 --- a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx +++ b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx @@ -169,14 +169,14 @@ export function InstanceRoutes({ if (error.type === ErrorType.TIMEOUT) { setGlobalNotification({ message: i18n.str`The request to the backend take too long and was cancelled`, - description: i18n.str`Diagnostic from ${error.info?.url} is "${error.message}"`, + description: i18n.str`Diagnostic from ${error.info.url} is "${error.message}"`, type: "ERROR", to, }); } else { setGlobalNotification({ message: i18n.str`The backend reported a problem: HTTP status #${error.status}`, - description: i18n.str`Diagnostic from ${error.info?.url} is '${error.message}'`, + description: i18n.str`Diagnostic from ${error.info.url} is '${error.message}'`, details: error.type === ErrorType.CLIENT || error.type === ErrorType.SERVER ? error.payload.detail @@ -601,12 +601,12 @@ function AdminInstanceUpdatePage({ error.type === ErrorType.TIMEOUT ? { message: i18n.str`The request to the backend take too long and was cancelled`, - description: i18n.str`Diagnostic from ${error.info?.url} is '${error.message}'`, + description: i18n.str`Diagnostic from ${error.info.url} is '${error.message}'`, type: "ERROR" as const, } : { message: i18n.str`The backend reported a problem: HTTP status #${error.status}`, - description: i18n.str`Diagnostic from ${error.info?.url} is '${error.message}'`, + description: i18n.str`Diagnostic from ${error.info.url} is '${error.message}'`, details: error.type === ErrorType.CLIENT || error.type === ErrorType.SERVER diff --git a/packages/merchant-backoffice-ui/src/hooks/backend.ts b/packages/merchant-backoffice-ui/src/hooks/backend.ts index 3610e0494..90fd320a9 100644 --- a/packages/merchant-backoffice-ui/src/hooks/backend.ts +++ b/packages/merchant-backoffice-ui/src/hooks/backend.ts @@ -70,7 +70,9 @@ export function useBackendInstancesTestForAdmin(): HttpResponse< useEffect(() => { request<Type>(`/management/instances`) .then((data) => setResult(data)) - .catch((error) => setResult(error)); + .catch((error: RequestError<MerchantBackend.ErrorDetail>) => + setResult(error.cause), + ); }, [request]); return result; @@ -78,14 +80,14 @@ export function useBackendInstancesTestForAdmin(): HttpResponse< export function useBackendConfig(): HttpResponse< MerchantBackend.VersionResponse, - MerchantBackend.ErrorDetail + RequestError<MerchantBackend.ErrorDetail> > { const { request } = useBackendBaseRequest(); type Type = MerchantBackend.VersionResponse; const [result, setResult] = useState< - HttpResponse<Type, MerchantBackend.ErrorDetail> + HttpResponse<Type, RequestError<MerchantBackend.ErrorDetail>> >({ loading: true }); useEffect(() => { diff --git a/packages/merchant-backoffice-ui/src/hooks/instance.ts b/packages/merchant-backoffice-ui/src/hooks/instance.ts index 8a882218b..eae65d64c 100644 --- a/packages/merchant-backoffice-ui/src/hooks/instance.ts +++ b/packages/merchant-backoffice-ui/src/hooks/instance.ts @@ -205,7 +205,7 @@ export function useInstanceDetails(): HttpResponse< if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -240,7 +240,7 @@ export function useInstanceKYCDetails(): HttpResponse< return { ok: true, data: { type: "redirect", status: data.data } }; return { ok: true, data: { type: "ok" } }; } - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -268,7 +268,7 @@ export function useManagedInstanceDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -285,6 +285,6 @@ export function useBackendInstances(): HttpResponse< if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } diff --git a/packages/merchant-backoffice-ui/src/hooks/order.ts b/packages/merchant-backoffice-ui/src/hooks/order.ts index a42d05966..e7a893f2c 100644 --- a/packages/merchant-backoffice-ui/src/hooks/order.ts +++ b/packages/merchant-backoffice-ui/src/hooks/order.ts @@ -150,7 +150,7 @@ export function useOrderDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -237,8 +237,8 @@ export function useInstanceOrders( if (beforeData) setLastBefore(beforeData); }, [afterData, beforeData]); - if (beforeError) return beforeError.info; - if (afterError) return afterError.info; + if (beforeError) return beforeError.cause; + if (afterError) return afterError.cause; // if the query returns less that we ask, then we have reach the end or beginning const isReachingEnd = afterData && afterData.data.orders.length < totalAfter; diff --git a/packages/merchant-backoffice-ui/src/hooks/product.ts b/packages/merchant-backoffice-ui/src/hooks/product.ts index d51e8de55..8ecaefaa6 100644 --- a/packages/merchant-backoffice-ui/src/hooks/product.ts +++ b/packages/merchant-backoffice-ui/src/hooks/product.ts @@ -122,8 +122,8 @@ export function useInstanceProducts(): HttpResponse< refreshWhenOffline: false, }); - if (listError) return listError.info; - if (productError) return productError.info; + if (listError) return listError.cause; + if (productError) return productError.cause; if (products) { const dataWithId = products.map((d) => { @@ -159,6 +159,6 @@ export function useProductDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } diff --git a/packages/merchant-backoffice-ui/src/hooks/reserves.ts b/packages/merchant-backoffice-ui/src/hooks/reserves.ts index edcce29cf..bb55b2474 100644 --- a/packages/merchant-backoffice-ui/src/hooks/reserves.ts +++ b/packages/merchant-backoffice-ui/src/hooks/reserves.ts @@ -129,7 +129,7 @@ export function useInstanceReserves(): HttpResponse< if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -154,7 +154,7 @@ export function useReserveDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } @@ -176,6 +176,6 @@ export function useTipDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } diff --git a/packages/merchant-backoffice-ui/src/hooks/templates.ts b/packages/merchant-backoffice-ui/src/hooks/templates.ts index 39a106537..56cdd3046 100644 --- a/packages/merchant-backoffice-ui/src/hooks/templates.ts +++ b/packages/merchant-backoffice-ui/src/hooks/templates.ts @@ -170,7 +170,7 @@ export function useInstanceTemplates( }, [afterData /*, beforeData*/]); // if (beforeError) return beforeError; - if (afterError) return afterError.info; + if (afterError) return afterError.cause; // if the query returns less that we ask, then we have reach the end or beginning const isReachingEnd = @@ -247,6 +247,6 @@ export function useTemplateDetails( if (data) { return data; } - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } diff --git a/packages/merchant-backoffice-ui/src/hooks/transfer.ts b/packages/merchant-backoffice-ui/src/hooks/transfer.ts index d3266e57c..27c3bdc75 100644 --- a/packages/merchant-backoffice-ui/src/hooks/transfer.ts +++ b/packages/merchant-backoffice-ui/src/hooks/transfer.ts @@ -133,8 +133,8 @@ export function useInstanceTransfers( if (beforeData) setLastBefore(beforeData); }, [afterData, beforeData]); - if (beforeError) return beforeError.info; - if (afterError) return afterError.info; + if (beforeError) return beforeError.cause; + if (afterError) return afterError.cause; // if the query returns less that we ask, then we have reach the end or beginning const isReachingEnd = diff --git a/packages/merchant-backoffice-ui/src/hooks/webhooks.ts b/packages/merchant-backoffice-ui/src/hooks/webhooks.ts index 7a8043441..c91fff8b4 100644 --- a/packages/merchant-backoffice-ui/src/hooks/webhooks.ts +++ b/packages/merchant-backoffice-ui/src/hooks/webhooks.ts @@ -116,7 +116,7 @@ export function useInstanceWebhooks( if (afterData) setLastAfter(afterData); }, [afterData]); - if (afterError) return afterError.info; + if (afterError) return afterError.cause; const isReachingEnd = afterData && afterData.data.webhooks.length < totalAfter; @@ -171,6 +171,6 @@ export function useWebhookDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error.info; + if (error) return error.cause; return { loading: true }; } |