fix(providers): surface import errors and refresh list on failed import

Tauri invoke rejects with the backend's serialized error string, not an
Error object, so reading `.message` produced an empty toast for every
failed live-config import. Route the rejection through
extractErrorMessage with a generic i18n fallback.

Also invalidate the providers query on import failure: the import
command can have visible side effects before erroring (e.g. GrokBuild
ensures its official entry prior to a failing import), and the list
must reflect them without a manual refresh.
This commit is contained in:
Jason
2026-07-21 15:31:05 +08:00
parent 6428e993a3
commit a5aa1fd82b
+8 -2
View File
@@ -20,6 +20,7 @@ import { toast } from "sonner";
import type { Provider } from "@/types";
import type { AppId } from "@/lib/api";
import { providersApi } from "@/lib/api/providers";
import { extractErrorMessage } from "@/utils/errorUtils";
import { useDragSort } from "@/hooks/useDragSort";
import {
useOpenClawLiveProviderIds,
@@ -239,8 +240,13 @@ export function ProviderList({
toast.info(t("provider.noProviders"));
}
},
onError: (error: Error) => {
toast.error(error.message);
onError: (error: unknown) => {
// Tauri invoke 的 reject 值是后端序列化出的纯字符串而非 Error 对象,
// 取 .message 只会得到 undefined(空 toast)。
toast.error(extractErrorMessage(error) || t("settings.importFailed"));
// 导入失败前也可能已产生需要上屏的副作用:GrokBuild 官方登录态下点
// 导入,命令层会先补种官方条目、随后才因 live 不可导入而报错。
queryClient.invalidateQueries({ queryKey: ["providers", appId] });
},
});