fix getting wrong error message after 401 response in merchant backoffice
This commit is contained in:
parent
f7481ba1d8
commit
da93d2ba7e
@ -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 =
|
||||
|
@ -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;
|
||||
|
@ -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 };
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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(() => {
|
||||
|
@ -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 };
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 };
|
||||
}
|
||||
|
@ -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 };
|
||||
}
|
||||
|
@ -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 };
|
||||
}
|
||||
|
@ -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 =
|
||||
|
@ -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 };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user