feat(openrouter): validate API key at save time

The stored key that caused the persistent 401s turned out to be only
9 characters long — an accepted-but-truncated paste. Prevent this class
of problem at the source:
- require a minimum key length in the zod schema
- verify new keys against OpenRouter's /api/v1/key endpoint on save,
  rejecting explicit 401/403 (network errors don't block saving)
- return zod validation messages as 400 instead of a generic 500
- surface the server's error message in the settings toast (desktop
  and mobile) instead of a generic failure text
This commit is contained in:
Claude committed 2026-07-14 06:39:01 +00:00
1 parent 75e1d88c26
commit 5550fb05d6
5 files changed
+48 -6

No files matched your search

+9 -2
View File
@@ -157,10 +157,17 @@ export default function SettingsMobile() {
});
setOpenrouterApiKey("");
},
onError: () => {
onError: (error: Error) => {
let description = "Impossible de sauvegarder la configuration OpenRouter";
const body = error.message.match(/^\d+:\s*(.+)$/)?.[1];
if (body) {
try {
description = JSON.parse(body).error || description;
} catch { /* garder le message générique */ }
}
toast({
title: "Erreur",
description: "Impossible de sauvegarder la configuration OpenRouter",
description,
variant: "destructive",
});
},
+9 -2
View File
@@ -161,10 +161,17 @@ export default function Settings() {
});
setOpenrouterApiKey(""); // Clear the API key after saving
},
onError: () => {
onError: (error: Error) => {
let description = "Impossible de sauvegarder la configuration OpenRouter";
const body = error.message.match(/^\d+:\s*(.+)$/)?.[1];
if (body) {
try {
description = JSON.parse(body).error || description;
} catch { /* garder le message générique */ }
}
toast({
title: "Erreur",
description: "Impossible de sauvegarder la configuration OpenRouter",
description,
variant: "destructive",
});
},