mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-31 19:22:15 +08:00
feat: differentiate fetch models error messages by failure type
Distinguish between missing API key, missing endpoint, auth failure, unsupported provider (404/405), and timeout errors instead of showing a generic failure toast for all cases.
This commit is contained in:
@@ -28,7 +28,11 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { ApiKeySection } from "./shared";
|
||||
import { fetchModelsForConfig, type FetchedModel } from "@/lib/api/model-fetch";
|
||||
import {
|
||||
fetchModelsForConfig,
|
||||
showFetchModelsError,
|
||||
type FetchedModel,
|
||||
} from "@/lib/api/model-fetch";
|
||||
import { opencodeNpmPackages } from "@/config/opencodeProviderPresets";
|
||||
import { cn } from "@/lib/utils";
|
||||
import {
|
||||
@@ -247,7 +251,10 @@ export function OpenCodeFormFields({
|
||||
|
||||
const handleFetchModels = useCallback(() => {
|
||||
if (!baseUrl || !apiKey) {
|
||||
toast.error(t("providerForm.fetchModelsFailed"));
|
||||
showFetchModelsError(null, t, {
|
||||
hasApiKey: !!apiKey,
|
||||
hasBaseUrl: !!baseUrl,
|
||||
});
|
||||
return;
|
||||
}
|
||||
setIsFetchingModels(true);
|
||||
@@ -264,7 +271,7 @@ export function OpenCodeFormFields({
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn("[ModelFetch] Failed:", err);
|
||||
toast.error(t("providerForm.fetchModelsFailed"));
|
||||
showFetchModelsError(err, t);
|
||||
})
|
||||
.finally(() => setIsFetchingModels(false));
|
||||
}, [baseUrl, apiKey, t]);
|
||||
|
||||
Reference in New Issue
Block a user