chore: enhance_verify_toast (#748)

This commit is contained in:
Wendong-Fan 2025-11-21 17:22:33 +08:00 committed by GitHub
commit f997bb9f5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -45,6 +45,12 @@ export default function SettingModels() {
useAuthStore();
const navigate = useNavigate();
const { t } = useTranslation();
const getValidateMessage = (res: any) =>
res?.message ??
res?.detail?.message ??
res?.detail?.error?.message ??
res?.error?.message ??
t("setting.validate-failed");
const [items, setItems] = useState<Provider[]>(
INIT_PROVODERS.filter((p) => p.id !== "local")
);
@ -226,7 +232,7 @@ const [errors, setErrors] = useState<
setErrors((prev) => {
const next = [...prev];
if (!next[idx]) next[idx] = {} as any;
next[idx].apiKey = res?.message || t("setting.validate-failed");
next[idx].apiKey = getValidateMessage(res);
return next;
});
return;
@ -238,9 +244,10 @@ const [errors, setErrors] = useState<
setErrors((prev) => {
const next = [...prev];
if (!next[idx]) next[idx] = {} as any;
next[idx].apiKey = t("setting.validate-failed");
next[idx].apiKey = getValidateMessage(e);
return next;
});
return;
} finally {
setLoading(null);
}
@ -369,7 +376,7 @@ const [errors, setErrors] = useState<
} else {
console.log("failed", res.message);
const toastId = toast(t("setting.validate-failed"), {
description: res.message,
description: getValidateMessage(res),
action: {
label: t("setting.close"),
onClick: () => {
@ -383,6 +390,16 @@ const [errors, setErrors] = useState<
console.log(res);
} catch (e) {
console.log(e);
const toastId = toast(t("setting.validate-failed"), {
description: getValidateMessage(e),
action: {
label: t("setting.close"),
onClick: () => {
toast.dismiss(toastId);
},
},
});
return;
} finally {
setLoading(null);
}