Skip to content

Commit

Permalink
fix: err tip
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Jan 25, 2025
1 parent 92105e9 commit 67b8a2b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 50 deletions.
2 changes: 1 addition & 1 deletion packages/web/hooks/useRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const useRequest2 = <TData, TParams extends any[]>(
...rest,
onError: (err, params) => {
rest?.onError?.(err, params);
if (errorToast !== undefined) {
if (errorToast !== '') {
const errText = t(getErrText(err, errorToast || '') as any);
if (errText) {
toast({
Expand Down
4 changes: 2 additions & 2 deletions packages/web/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
"code_error.team_error.org_parent_not_exist": "Parent organization does not exist",
"code_error.team_error.over_size": "error.team.overSize",
"code_error.team_error.plugin_amount_not_enough": "Plugin Limit Reached",
"code_error.team_error.re_rank_not_enough": "Unauthorized to Use Re-Rank",
"code_error.team_error.re_rank_not_enough": "Search rearrangement cannot be used in the free version~",
"code_error.team_error.un_auth": "Unauthorized to Operate This Team",
"code_error.team_error.user_not_active": "The user did not accept or has left the team",
"code_error.team_error.website_sync_not_enough": "Unauthorized to Use Website Sync",
"code_error.team_error.website_sync_not_enough": "The free version cannot be synchronized with the web site ~",
"code_error.token_error_code.403": "Invalid Login Status, Please Re-login",
"code_error.user_error.balance_not_enough": "Insufficient Account Balance",
"code_error.user_error.bin_visitor_guest": "You Are Currently a Guest, Unauthorized to Operate",
Expand Down
4 changes: 2 additions & 2 deletions packages/web/i18n/zh-CN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@
"code_error.team_error.org_parent_not_exist": "父部门不存在",
"code_error.team_error.over_size": "error.team.overSize",
"code_error.team_error.plugin_amount_not_enough": "插件数量已达上限~",
"code_error.team_error.re_rank_not_enough": "无权使用检索重排~",
"code_error.team_error.re_rank_not_enough": "免费版无法使用检索重排~",
"code_error.team_error.un_auth": "无权操作该团队",
"code_error.team_error.user_not_active": "用户未接受或已离开团队",
"code_error.team_error.website_sync_not_enough": "无权使用Web站点同步~",
"code_error.team_error.website_sync_not_enough": "免费版无法使用Web站点同步~",
"code_error.token_error_code.403": "登录状态无效,请重新登录",
"code_error.user_error.balance_not_enough": "账号余额不足~",
"code_error.user_error.bin_visitor_guest": "您当前身份为游客,无权操作",
Expand Down
4 changes: 2 additions & 2 deletions packages/web/i18n/zh-Hant/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@
"code_error.team_error.org_parent_not_exist": "父組織不存在",
"code_error.team_error.over_size": "error.team.overSize",
"code_error.team_error.plugin_amount_not_enough": "已達外掛程式數量上限",
"code_error.team_error.re_rank_not_enough": "無權使用結果重新排名",
"code_error.team_error.re_rank_not_enough": "免費版無法使用檢索重排~",
"code_error.team_error.un_auth": "無權操作此團隊",
"code_error.team_error.user_not_active": "使用者未接受或已離開團隊",
"code_error.team_error.website_sync_not_enough": "無權使用網站同步",
"code_error.team_error.website_sync_not_enough": "免費版無法使用Web站點同步~",
"code_error.token_error_code.403": "登入狀態無效,請重新登入",
"code_error.user_error.balance_not_enough": "帳戶餘額不足",
"code_error.user_error.bin_visitor_guest": "您目前身份為訪客,無權操作",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ const NotSufficientModal = ({ type }: { type: NotSufficientModalType }) => {
[TeamErrEnum.datasetSizeNotEnough]: t('common:support.wallet.Dataset_not_sufficient'),
[TeamErrEnum.datasetAmountNotEnough]: t('common:support.wallet.Dataset_amount_not_sufficient'),
[TeamErrEnum.teamMemberOverSize]: t('common:support.wallet.Team_member_over_size'),
[TeamErrEnum.appAmountNotEnough]: t('common:support.wallet.App_amount_not_sufficient')
[TeamErrEnum.appAmountNotEnough]: t('common:support.wallet.App_amount_not_sufficient'),
[TeamErrEnum.pluginAmountNotEnough]: t('common:support.wallet.App_amount_not_sufficient'),
[TeamErrEnum.websiteSyncNotEnough]: t('common:code_error.team_error.website_sync_not_enough'),
[TeamErrEnum.reRankNotEnough]: t('common:code_error.team_error.re_rank_not_enough')
};

return (
Expand Down
41 changes: 11 additions & 30 deletions projects/app/src/components/support/wallet/QRCodePayModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useTranslation } from 'next-i18next';
import { Box, ModalBody } from '@chakra-ui/react';
import { checkBalancePayResult } from '@/web/support/wallet/bill/api';
import { useToast } from '@fastgpt/web/hooks/useToast';
import { getErrText } from '@fastgpt/global/common/error/utils';
import LightTip from '@fastgpt/web/components/common/LightTip';
import QRCode from 'qrcode';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';

export type QRPayProps = {
readPrice: number;
Expand Down Expand Up @@ -54,35 +54,16 @@ const QRCodePayModal = ({
drawCode();
}, [drawCode]);

useEffect(() => {
let timer: NodeJS.Timeout;
const check = async () => {
try {
const res = await checkBalancePayResult(billId);
if (res) {
try {
await onSuccess?.();
toast({
title: res,
status: 'success'
});
return clearTimeout(timer);
} catch (error) {
toast({
title: getErrText(error),
status: 'error'
});
}
}
} catch (error) {}
clearTimeout(timer);
timer = setTimeout(check, 2000);
};

check();

return () => clearTimeout(timer);
}, [billId, drawCode, onSuccess, toast]);
useRequest2(() => checkBalancePayResult(billId), {
manual: false,
pollingInterval: 2000,
onSuccess: (res) => {
if (res) {
onSuccess?.();
}
},
errorToast: ''
});

return (
<MyModal isOpen title={t('common:user.Pay')} iconSrc="/imgs/modal/pay.svg">
Expand Down
27 changes: 16 additions & 11 deletions projects/app/src/web/common/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,20 @@ function checkRes(data: ResponseDataType) {
*/
function responseError(err: any) {
console.log('error->', '请求错误', err);
const data = err?.response?.data || err;

if (!err) {
return Promise.reject({ message: '未知错误' });
}
if (typeof err === 'string') {
return Promise.reject({ message: err });
}
if (typeof data === 'string') {
return Promise.reject(data);
}

// 有报错响应
if (err?.code in TOKEN_ERROR_CODE || err?.response?.data?.code in TOKEN_ERROR_CODE) {
if (data?.code in TOKEN_ERROR_CODE) {
if (!['/chat/share', '/chat/team', '/login'].includes(window.location.pathname)) {
clearToken();
window.location.replace(
Expand All @@ -120,18 +125,18 @@ function responseError(err: any) {
return Promise.reject({ message: i18nT('common:unauth_token') });
}
if (
err?.statusText === TeamErrEnum.aiPointsNotEnough ||
err?.statusText === TeamErrEnum.datasetSizeNotEnough ||
err?.statusText === TeamErrEnum.datasetAmountNotEnough ||
err?.statusText === TeamErrEnum.appAmountNotEnough
data?.statusText === TeamErrEnum.aiPointsNotEnough ||
data?.statusText === TeamErrEnum.datasetSizeNotEnough ||
data?.statusText === TeamErrEnum.datasetAmountNotEnough ||
data?.statusText === TeamErrEnum.appAmountNotEnough ||
data?.statusText === TeamErrEnum.pluginAmountNotEnough ||
data?.statusText === TeamErrEnum.websiteSyncNotEnough ||
data?.statusText === TeamErrEnum.reRankNotEnough
) {
useSystemStore.getState().setNotSufficientModalType(err.statusText);
return Promise.reject(err);
}
if (err?.response?.data) {
return Promise.reject(err?.response?.data);
useSystemStore.getState().setNotSufficientModalType(data.statusText);
return Promise.reject(data);
}
return Promise.reject(err);
return Promise.reject(data);
}

/* 创建请求实例 */
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/web/context/useInitApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const useInitApp = () => {

useRequest2(initFetch, {
manual: false,
pollingInterval: 300000
pollingInterval: 300000 // 5 minutes refresh
});

useEffect(() => {
Expand Down

0 comments on commit 67b8a2b

Please sign in to comment.