From 53af8b486fd8a538c1f54a2ce66ed5f74b2b46ed Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 10 Feb 2023 09:50:54 -0300 Subject: [PATCH] fix: request error is whats being thrown --- .../src/hooks/backend.ts | 3 +-- .../src/hooks/instance.ts | 26 +++++++++---------- .../merchant-backoffice-ui/src/hooks/order.ts | 24 ++++++++--------- .../src/hooks/product.ts | 18 ++++++------- .../src/hooks/reserves.ts | 18 ++++++------- .../src/hooks/templates.ts | 20 +++++++------- .../src/hooks/transfer.ts | 20 +++++++------- .../src/hooks/webhooks.ts | 20 +++++++------- 8 files changed, 74 insertions(+), 75 deletions(-) diff --git a/packages/merchant-backoffice-ui/src/hooks/backend.ts b/packages/merchant-backoffice-ui/src/hooks/backend.ts index 952b33f7e..6c4e5c176 100644 --- a/packages/merchant-backoffice-ui/src/hooks/backend.ts +++ b/packages/merchant-backoffice-ui/src/hooks/backend.ts @@ -47,8 +47,7 @@ export function useMatchMutate(): ( const allKeys = Array.from(cache.keys()); const keys = allKeys.filter((key) => re.test(key)); const mutations = keys.map((key) => { - // console.log(key) - mutate(key, value, true); + return mutate(key, value, true); }); return Promise.all(mutations); }; diff --git a/packages/merchant-backoffice-ui/src/hooks/instance.ts b/packages/merchant-backoffice-ui/src/hooks/instance.ts index f118e1e6e..0b00936cd 100644 --- a/packages/merchant-backoffice-ui/src/hooks/instance.ts +++ b/packages/merchant-backoffice-ui/src/hooks/instance.ts @@ -13,14 +13,14 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ +import { + HttpResponse, + HttpResponseOk, + RequestError, +} from "@gnu-taler/web-util/lib/index.browser"; import useSWR, { useSWRConfig } from "swr"; import { useBackendContext } from "../context/backend.js"; import { MerchantBackend } from "../declaration.js"; -import { - HttpError, - HttpResponse, - HttpResponseOk, -} from "@gnu-taler/web-util/lib/index.browser"; import { useBackendBaseRequest, useBackendInstanceRequest, @@ -188,7 +188,7 @@ export function useInstanceDetails(): HttpResponse< const { data, error, isValidating } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/`], fetcher, { refreshInterval: 0, refreshWhenHidden: false, @@ -202,7 +202,7 @@ export function useInstanceDetails(): HttpResponse< if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error; + if (error) return error.info; return { loading: true }; } @@ -218,7 +218,7 @@ export function useInstanceKYCDetails(): HttpResponse< const { data, error } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/kyc`], fetcher, { refreshInterval: 5000, refreshWhenHidden: false, @@ -235,7 +235,7 @@ export function useInstanceKYCDetails(): HttpResponse< return { ok: true, data: { type: "redirect", status: data.data } }; return { ok: true, data: { type: "ok" } }; } - if (error) return error; + if (error) return error.info; return { loading: true }; } @@ -249,7 +249,7 @@ export function useManagedInstanceDetails( const { data, error, isValidating } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/management/instances/${instanceId}`], request, { refreshInterval: 0, refreshWhenHidden: false, @@ -263,7 +263,7 @@ export function useManagedInstanceDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error; + if (error) return error.info; return { loading: true }; } @@ -275,11 +275,11 @@ export function useBackendInstances(): HttpResponse< const { data, error, isValidating } = useSWR< HttpResponseOk, - HttpError + RequestError >(["/management/instances"], request); if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error; + if (error) return error.info; return { loading: true }; } diff --git a/packages/merchant-backoffice-ui/src/hooks/order.ts b/packages/merchant-backoffice-ui/src/hooks/order.ts index c01f8dd83..3bcf7aaab 100644 --- a/packages/merchant-backoffice-ui/src/hooks/order.ts +++ b/packages/merchant-backoffice-ui/src/hooks/order.ts @@ -13,16 +13,16 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ +import { + HttpResponse, + HttpResponseOk, + HttpResponsePaginated, + RequestError, +} from "@gnu-taler/web-util/lib/index.browser"; import { useEffect, useState } from "preact/hooks"; import useSWR from "swr"; import { MerchantBackend } from "../declaration.js"; import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js"; -import { - HttpError, - HttpResponse, - HttpResponseOk, - HttpResponsePaginated, -} from "@gnu-taler/web-util/lib/index.browser"; import { useBackendInstanceRequest, useMatchMutate } from "./backend.js"; export interface OrderAPI { @@ -136,7 +136,7 @@ export function useOrderDetails( const { data, error, isValidating } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/orders/${oderId}`], fetcher, { refreshInterval: 0, refreshWhenHidden: false, @@ -147,7 +147,7 @@ export function useOrderDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error; + if (error) return error.info; return { loading: true }; } @@ -185,7 +185,7 @@ export function useInstanceOrders( isValidating: loadingBefore, } = useSWR< HttpResponseOk, - HttpError + RequestError >( [ `/private/orders`, @@ -203,7 +203,7 @@ export function useInstanceOrders( isValidating: loadingAfter, } = useSWR< HttpResponseOk, - HttpError + RequestError >( [ `/private/orders`, @@ -234,8 +234,8 @@ export function useInstanceOrders( if (beforeData) setLastBefore(beforeData); }, [afterData, beforeData]); - if (beforeError) return beforeError; - if (afterError) return afterError; + if (beforeError) return beforeError.info; + if (afterError) return afterError.info; // 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 5d95a2f8f..df86f68f5 100644 --- a/packages/merchant-backoffice-ui/src/hooks/product.ts +++ b/packages/merchant-backoffice-ui/src/hooks/product.ts @@ -13,13 +13,13 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ -import useSWR, { useSWRConfig } from "swr"; -import { MerchantBackend, WithId } from "../declaration.js"; import { - HttpError, HttpResponse, HttpResponseOk, + RequestError, } from "@gnu-taler/web-util/lib/index.browser"; +import useSWR, { useSWRConfig } from "swr"; +import { MerchantBackend, WithId } from "../declaration.js"; import { useBackendInstanceRequest, useMatchMutate } from "./backend.js"; export interface ProductAPI { @@ -96,7 +96,7 @@ export function useInstanceProducts(): HttpResponse< const { data: list, error: listError } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/products`], fetcher, { refreshInterval: 0, refreshWhenHidden: false, @@ -110,7 +110,7 @@ export function useInstanceProducts(): HttpResponse< ); const { data: products, error: productError } = useSWR< HttpResponseOk[], - HttpError + RequestError >([paths], multiFetcher, { refreshInterval: 0, refreshWhenHidden: false, @@ -119,8 +119,8 @@ export function useInstanceProducts(): HttpResponse< refreshWhenOffline: false, }); - if (listError) return listError; - if (productError) return productError; + if (listError) return listError.info; + if (productError) return productError.info; if (products) { const dataWithId = products.map((d) => { @@ -145,7 +145,7 @@ export function useProductDetails( const { data, error, isValidating } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/products/${productId}`], fetcher, { refreshInterval: 0, refreshWhenHidden: false, @@ -156,6 +156,6 @@ export function useProductDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error; + if (error) return error.info; return { loading: true }; } diff --git a/packages/merchant-backoffice-ui/src/hooks/reserves.ts b/packages/merchant-backoffice-ui/src/hooks/reserves.ts index 0215f32c5..a4c0a7e55 100644 --- a/packages/merchant-backoffice-ui/src/hooks/reserves.ts +++ b/packages/merchant-backoffice-ui/src/hooks/reserves.ts @@ -13,13 +13,13 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ -import useSWR, { useSWRConfig } from "swr"; -import { MerchantBackend } from "../declaration.js"; import { - HttpError, HttpResponse, HttpResponseOk, + RequestError, } from "@gnu-taler/web-util/lib/index.browser"; +import useSWR, { useSWRConfig } from "swr"; +import { MerchantBackend } from "../declaration.js"; import { useBackendInstanceRequest, useMatchMutate } from "./backend.js"; export function useReservesAPI(): ReserveMutateAPI { @@ -121,12 +121,12 @@ export function useInstanceReserves(): HttpResponse< const { data, error, isValidating } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/reserves`], fetcher); if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error; + if (error) return error.info; return { loading: true }; } @@ -140,7 +140,7 @@ export function useReserveDetails( const { data, error, isValidating } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/reserves/${reserveId}`], reserveDetailFetcher, { refreshInterval: 0, refreshWhenHidden: false, @@ -151,7 +151,7 @@ export function useReserveDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error; + if (error) return error.info; return { loading: true }; } @@ -162,7 +162,7 @@ export function useTipDetails( const { data, error, isValidating } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/tips/${tipId}`], tipsDetailFetcher, { refreshInterval: 0, refreshWhenHidden: false, @@ -173,6 +173,6 @@ export function useTipDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error; + if (error) return error.info; return { loading: true }; } diff --git a/packages/merchant-backoffice-ui/src/hooks/templates.ts b/packages/merchant-backoffice-ui/src/hooks/templates.ts index 124786887..579478537 100644 --- a/packages/merchant-backoffice-ui/src/hooks/templates.ts +++ b/packages/merchant-backoffice-ui/src/hooks/templates.ts @@ -13,17 +13,17 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ -import { MerchantBackend } from "../declaration.js"; -import { useMatchMutate, useBackendInstanceRequest } from "./backend.js"; -import useSWR from "swr"; -import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js"; -import { useEffect, useState } from "preact/hooks"; import { - HttpError, HttpResponse, HttpResponseOk, HttpResponsePaginated, + RequestError, } from "@gnu-taler/web-util/lib/index.browser"; +import { useEffect, useState } from "preact/hooks"; +import useSWR from "swr"; +import { MerchantBackend } from "../declaration.js"; +import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js"; +import { useBackendInstanceRequest, useMatchMutate } from "./backend.js"; export function useTemplateAPI(): TemplateAPI { const mutateAll = useMatchMutate(); @@ -148,7 +148,7 @@ export function useInstanceTemplates( isValidating: loadingAfter, } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/templates`, args?.position, -totalAfter], templateFetcher); //this will save last result @@ -167,7 +167,7 @@ export function useInstanceTemplates( }, [afterData /*, beforeData*/]); // if (beforeError) return beforeError; - if (afterError) return afterError; + if (afterError) return afterError.info; // if the query returns less that we ask, then we have reach the end or beginning const isReachingEnd = @@ -231,7 +231,7 @@ export function useTemplateDetails( const { data, error, isValidating } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/templates/${templateId}`], templateFetcher, { refreshInterval: 0, refreshWhenHidden: false, @@ -242,6 +242,6 @@ export function useTemplateDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error; + if (error) return error.info; return { loading: true }; } diff --git a/packages/merchant-backoffice-ui/src/hooks/transfer.ts b/packages/merchant-backoffice-ui/src/hooks/transfer.ts index 6b30047e9..0f9d79f24 100644 --- a/packages/merchant-backoffice-ui/src/hooks/transfer.ts +++ b/packages/merchant-backoffice-ui/src/hooks/transfer.ts @@ -13,16 +13,16 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ +import { + HttpResponse, + HttpResponseOk, + HttpResponsePaginated, + RequestError, +} from "@gnu-taler/web-util/lib/index.browser"; import { useEffect, useState } from "preact/hooks"; import useSWR from "swr"; import { MerchantBackend } from "../declaration.js"; import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js"; -import { - HttpError, - HttpResponse, - HttpResponseOk, - HttpResponsePaginated, -} from "@gnu-taler/web-util/lib/index.browser"; import { useBackendInstanceRequest, useMatchMutate } from "./backend.js"; export function useTransferAPI(): TransferAPI { @@ -91,7 +91,7 @@ export function useInstanceTransfers( isValidating: loadingBefore, } = useSWR< HttpResponseOk, - HttpError + RequestError >( [ `/private/transfers`, @@ -108,7 +108,7 @@ export function useInstanceTransfers( isValidating: loadingAfter, } = useSWR< HttpResponseOk, - HttpError + RequestError >( [ `/private/transfers`, @@ -138,8 +138,8 @@ export function useInstanceTransfers( if (beforeData) setLastBefore(beforeData); }, [afterData, beforeData]); - if (beforeError) return beforeError; - if (afterError) return afterError; + if (beforeError) return beforeError.info; + if (afterError) return afterError.info; // 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 e1cd3daf2..9cf6fae03 100644 --- a/packages/merchant-backoffice-ui/src/hooks/webhooks.ts +++ b/packages/merchant-backoffice-ui/src/hooks/webhooks.ts @@ -13,17 +13,17 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ -import { MerchantBackend } from "../declaration.js"; -import { useMatchMutate, useBackendInstanceRequest } from "./backend.js"; -import useSWR from "swr"; -import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js"; -import { useEffect, useState } from "preact/hooks"; import { - HttpError, HttpResponse, HttpResponseOk, HttpResponsePaginated, + RequestError, } from "@gnu-taler/web-util/lib/index.browser"; +import { useEffect, useState } from "preact/hooks"; +import useSWR from "swr"; +import { MerchantBackend } from "../declaration.js"; +import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js"; +import { useBackendInstanceRequest, useMatchMutate } from "./backend.js"; export function useWebhookAPI(): WebhookAPI { const mutateAll = useMatchMutate(); @@ -100,7 +100,7 @@ export function useInstanceWebhooks( isValidating: loadingAfter, } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/webhooks`, args?.position, -totalAfter], webhookFetcher); const [lastAfter, setLastAfter] = useState< @@ -113,7 +113,7 @@ export function useInstanceWebhooks( if (afterData) setLastAfter(afterData); }, [afterData]); - if (afterError) return afterError; + if (afterError) return afterError.info; const isReachingEnd = afterData && afterData.data.webhooks.length < totalAfter; @@ -157,7 +157,7 @@ export function useWebhookDetails( const { data, error, isValidating } = useSWR< HttpResponseOk, - HttpError + RequestError >([`/private/webhooks/${webhookId}`], webhookFetcher, { refreshInterval: 0, refreshWhenHidden: false, @@ -168,6 +168,6 @@ export function useWebhookDetails( if (isValidating) return { loading: true, data: data?.data }; if (data) return data; - if (error) return error; + if (error) return error.info; return { loading: true }; }