Skip to content

Commit 0cc4e4e

Browse files
committed
fix: improve error handling for LLM authentication by providing specific error messages for locked API keys
1 parent 0907efa commit 0cc4e4e

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/app/[owner]/[repo]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ ${context}`,
929929
} catch (err) {
930930
const errorMessage = err instanceof Error ? err.message : String(err);
931931
if (shouldPromptForLLMSettings(errorMessage)) {
932-
setToastMessage("LLM authentication failed. Open LLM Settings to update your API key.");
932+
setToastMessage(errorMessage);
933933
if (typeof window !== "undefined") {
934934
window.dispatchEvent(new Event("gitask-open-llm-settings"));
935935
}

src/lib/llm.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,25 @@ export interface ChatMessage {
5353
content: string;
5454
}
5555

56+
const VAULT_LOCKED_MSG = "Your API key is locked. Open LLM Settings and unlock it to continue.";
57+
58+
function isVaultLockedError(lower: string): boolean {
59+
return (
60+
lower.includes("vault is locked") ||
61+
lower.includes("key is locked") ||
62+
lower.includes("not unlocked") ||
63+
lower.includes("locked") && lower.includes("unlock")
64+
);
65+
}
66+
5667
function normalizeGeminiError(err: unknown): Error {
5768
const message = err instanceof Error ? err.message : String(err);
5869
const lower = message.toLowerCase();
5970

71+
if (isVaultLockedError(lower)) {
72+
return new Error(VAULT_LOCKED_MSG);
73+
}
74+
6075
if (
6176
lower.includes("api key not valid") ||
6277
lower.includes("invalid api key") ||
@@ -82,6 +97,10 @@ function normalizeGroqError(err: unknown): Error {
8297
const message = err instanceof Error ? err.message : String(err);
8398
const lower = message.toLowerCase();
8499

100+
if (isVaultLockedError(lower)) {
101+
return new Error(VAULT_LOCKED_MSG);
102+
}
103+
85104
if (
86105
lower.includes("invalid api key") ||
87106
lower.includes("authentication") ||
@@ -879,7 +898,7 @@ export async function initLLM(
879898
storageMode === "local"
880899
? `Add your ${providerLabel} API key in LLM Settings.`
881900
: state === "locked"
882-
? "Please unlock your API key in Settings."
901+
? VAULT_LOCKED_MSG
883902
: "Add an API key in Settings or use the default key."
884903
);
885904
}

0 commit comments

Comments
 (0)