fix getting wrong error message after 401 response in merchant backoffice

This commit is contained in:
Sebastian 2023-05-12 11:23:38 -03:00
parent f7481ba1d8
commit da93d2ba7e
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069
12 changed files with 39 additions and 35 deletions

View File

@ -209,7 +209,7 @@ export function useAccountDetails(
}); });
return clone; return clone;
} }
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }
@ -239,7 +239,7 @@ export function useWithdrawalDetails(
// if (isValidating) return { loading: true, data: data?.data }; // if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }
@ -269,7 +269,7 @@ export function useTransactionDetails(
// if (isValidating) return { loading: true, data: data?.data }; // if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }
@ -307,7 +307,7 @@ export function usePublicAccounts(
if (afterData) setLastAfter(afterData); if (afterData) setLastAfter(afterData);
}, [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 // if the query returns less that we ask, then we have reach the end or beginning
const isReachingEnd = const isReachingEnd =

View File

@ -347,7 +347,9 @@ export function useBackendConfig(): HttpResponse<
useEffect(() => { useEffect(() => {
request<Type>(`/config`) request<Type>(`/config`)
.then((data) => setResult(data)) .then((data) => setResult(data))
.catch((error) => setResult(error)); .catch((error: RequestError<SandboxBackend.SandboxError>) =>
setResult(error.cause),
);
}, [request]); }, [request]);
return result; return result;

View File

@ -379,7 +379,7 @@ export function useBusinessAccountDetails(
}); });
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }
@ -406,7 +406,7 @@ export function useRatiosAndFeeConfig(): HttpResponse<
}); });
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }
@ -479,7 +479,7 @@ export function useBusinessAccounts(
return { ok: true as const, data: { customers }, ...pagination }; return { ok: true as const, data: { customers }, ...pagination };
}, [afterData?.data]); }, [afterData?.data]);
if (afterError) return afterError.info; if (afterError) return afterError.cause;
if (afterData) { if (afterData) {
return result; return result;
} }
@ -565,6 +565,6 @@ export function useCashoutDetails(
}); });
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }

View File

@ -169,14 +169,14 @@ export function InstanceRoutes({
if (error.type === ErrorType.TIMEOUT) { if (error.type === ErrorType.TIMEOUT) {
setGlobalNotification({ setGlobalNotification({
message: i18n.str`The request to the backend take too long and was cancelled`, 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", type: "ERROR",
to, to,
}); });
} else { } else {
setGlobalNotification({ setGlobalNotification({
message: i18n.str`The backend reported a problem: HTTP status #${error.status}`, 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: details:
error.type === ErrorType.CLIENT || error.type === ErrorType.SERVER error.type === ErrorType.CLIENT || error.type === ErrorType.SERVER
? error.payload.detail ? error.payload.detail
@ -601,12 +601,12 @@ function AdminInstanceUpdatePage({
error.type === ErrorType.TIMEOUT error.type === ErrorType.TIMEOUT
? { ? {
message: i18n.str`The request to the backend take too long and was cancelled`, 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, type: "ERROR" as const,
} }
: { : {
message: i18n.str`The backend reported a problem: HTTP status #${error.status}`, 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: details:
error.type === ErrorType.CLIENT || error.type === ErrorType.CLIENT ||
error.type === ErrorType.SERVER error.type === ErrorType.SERVER

View File

@ -70,7 +70,9 @@ export function useBackendInstancesTestForAdmin(): HttpResponse<
useEffect(() => { useEffect(() => {
request<Type>(`/management/instances`) request<Type>(`/management/instances`)
.then((data) => setResult(data)) .then((data) => setResult(data))
.catch((error) => setResult(error)); .catch((error: RequestError<MerchantBackend.ErrorDetail>) =>
setResult(error.cause),
);
}, [request]); }, [request]);
return result; return result;
@ -78,14 +80,14 @@ export function useBackendInstancesTestForAdmin(): HttpResponse<
export function useBackendConfig(): HttpResponse< export function useBackendConfig(): HttpResponse<
MerchantBackend.VersionResponse, MerchantBackend.VersionResponse,
MerchantBackend.ErrorDetail RequestError<MerchantBackend.ErrorDetail>
> { > {
const { request } = useBackendBaseRequest(); const { request } = useBackendBaseRequest();
type Type = MerchantBackend.VersionResponse; type Type = MerchantBackend.VersionResponse;
const [result, setResult] = useState< const [result, setResult] = useState<
HttpResponse<Type, MerchantBackend.ErrorDetail> HttpResponse<Type, RequestError<MerchantBackend.ErrorDetail>>
>({ loading: true }); >({ loading: true });
useEffect(() => { useEffect(() => {

View File

@ -205,7 +205,7 @@ export function useInstanceDetails(): HttpResponse<
if (isValidating) return { loading: true, data: data?.data }; if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; 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: "redirect", status: data.data } };
return { ok: true, data: { type: "ok" } }; return { ok: true, data: { type: "ok" } };
} }
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }
@ -268,7 +268,7 @@ export function useManagedInstanceDetails(
if (isValidating) return { loading: true, data: data?.data }; if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }
@ -285,6 +285,6 @@ export function useBackendInstances(): HttpResponse<
if (isValidating) return { loading: true, data: data?.data }; if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }

View File

@ -150,7 +150,7 @@ export function useOrderDetails(
if (isValidating) return { loading: true, data: data?.data }; if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }
@ -237,8 +237,8 @@ export function useInstanceOrders(
if (beforeData) setLastBefore(beforeData); if (beforeData) setLastBefore(beforeData);
}, [afterData, beforeData]); }, [afterData, beforeData]);
if (beforeError) return beforeError.info; if (beforeError) return beforeError.cause;
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 // if the query returns less that we ask, then we have reach the end or beginning
const isReachingEnd = afterData && afterData.data.orders.length < totalAfter; const isReachingEnd = afterData && afterData.data.orders.length < totalAfter;

View File

@ -122,8 +122,8 @@ export function useInstanceProducts(): HttpResponse<
refreshWhenOffline: false, refreshWhenOffline: false,
}); });
if (listError) return listError.info; if (listError) return listError.cause;
if (productError) return productError.info; if (productError) return productError.cause;
if (products) { if (products) {
const dataWithId = products.map((d) => { const dataWithId = products.map((d) => {
@ -159,6 +159,6 @@ export function useProductDetails(
if (isValidating) return { loading: true, data: data?.data }; if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }

View File

@ -129,7 +129,7 @@ export function useInstanceReserves(): HttpResponse<
if (isValidating) return { loading: true, data: data?.data }; if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }
@ -154,7 +154,7 @@ export function useReserveDetails(
if (isValidating) return { loading: true, data: data?.data }; if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }
@ -176,6 +176,6 @@ export function useTipDetails(
if (isValidating) return { loading: true, data: data?.data }; if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }

View File

@ -170,7 +170,7 @@ export function useInstanceTemplates(
}, [afterData /*, beforeData*/]); }, [afterData /*, beforeData*/]);
// if (beforeError) return beforeError; // 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 // if the query returns less that we ask, then we have reach the end or beginning
const isReachingEnd = const isReachingEnd =
@ -247,6 +247,6 @@ export function useTemplateDetails(
if (data) { if (data) {
return data; return data;
} }
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }

View File

@ -133,8 +133,8 @@ export function useInstanceTransfers(
if (beforeData) setLastBefore(beforeData); if (beforeData) setLastBefore(beforeData);
}, [afterData, beforeData]); }, [afterData, beforeData]);
if (beforeError) return beforeError.info; if (beforeError) return beforeError.cause;
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 // if the query returns less that we ask, then we have reach the end or beginning
const isReachingEnd = const isReachingEnd =

View File

@ -116,7 +116,7 @@ export function useInstanceWebhooks(
if (afterData) setLastAfter(afterData); if (afterData) setLastAfter(afterData);
}, [afterData]); }, [afterData]);
if (afterError) return afterError.info; if (afterError) return afterError.cause;
const isReachingEnd = const isReachingEnd =
afterData && afterData.data.webhooks.length < totalAfter; afterData && afterData.data.webhooks.length < totalAfter;
@ -171,6 +171,6 @@ export function useWebhookDetails(
if (isValidating) return { loading: true, data: data?.data }; if (isValidating) return { loading: true, data: data?.data };
if (data) return data; if (data) return data;
if (error) return error.info; if (error) return error.cause;
return { loading: true }; return { loading: true };
} }