srbhr/Resume-Matcher · error · Error
${data.detail || Failed to clear API keys (status ${res.stat
Error message
${data.detail || Failed to clear API keys (status ${res.status}).} What it means
clearAllApiKeys performs DELETE /config/api-keys?confirm=CLEAR_ALL_KEYS and throws this on any non-ok response, again preferring the backend `detail` message. The confirm query parameter is required by the backend; without it the server rejects the destructive bulk operation.
Source
Thrown at apps/frontend/lib/api/config.ts:528
credentials: 'include',
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
throw new Error(data.detail || `Failed to delete API key (status ${res.status}).`);
}
}
// Clear all API keys
export async function clearAllApiKeys(): Promise<void> {
const res = await apiFetch('/config/api-keys?confirm=CLEAR_ALL_KEYS', {
method: 'DELETE',
credentials: 'include',
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
throw new Error(data.detail || `Failed to clear API keys (status ${res.status}).`);
}
}
// Reset database
export async function resetDatabase(): Promise<void> {
const res = await apiFetch('/config/reset', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ confirm: 'RESET_ALL_DATA' }),
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
throw new Error(data.detail || `Failed to reset database (status ${res.status}).`);
}
}
View on GitHub (pinned to 116f9cc3b0)
Solutions
- Ensure the exact confirm token `CLEAR_ALL_KEYS` is sent as ?confirm=CLEAR_ALL_KEYS — any deviation makes the backend refuse.
- 401/403 → re-authenticate and retry; 5xx → inspect backend logs and key-store volume permissions.
- Confirm the user intent in the UI (confirm-dialog) before calling, since this is irreversible.
- Catch in handleClearApiKeys, display the detail, and re-fetch key status so the UI reflects what actually happened.
Example fix
// before
const res = await apiFetch('/config/api-keys', { method: 'DELETE', credentials: 'include' });
// after
const res = await apiFetch('/config/api-keys?confirm=CLEAR_ALL_KEYS', {
method: 'DELETE',
credentials: 'include',
}); Defensive patterns
Strategy: validation
Validate before calling
const CONFIRM = 'CLEAR_ALL_KEYS';
const url = `/config/api-keys?confirm=${encodeURIComponent(CONFIRM)}`;
if (!url.includes('confirm=CLEAR_ALL_KEYS')) throw new Error('confirm token required'); Type guard
function hasClearAllConfirm(params: URLSearchParams): boolean {
return params.get('confirm') === 'CLEAR_ALL_KEYS';
} Try / catch
const ok = await confirmDialog({
title: 'Clear all API keys?',
tone: 'destructive',
});
if (!ok) return;
try {
await clearAllApiKeys();
showToast('All keys cleared');
} catch (e) {
showToast(e instanceof Error ? e.message : 'Clear failed');
} Prevention
- Never hand-build the request without the exact confirm token
- Require an explicit user confirmation dialog before bulk destructive ops
- Re-fetch key status after clearing so the UI matches server state
- Check backend key-store volume permissions when 5xx persists
When it happens
Trigger: Non-2xx on the bulk-clear DELETE: 400/403 when the confirm=CLEAR_ALL_KEYS parameter is missing/incorrect (safety check), 401 (expired session), 404 (route/proxy misconfiguration), 500 (key-store wipe failed).
Common situations: Manually constructing the request and forgetting the confirm param; clicking 'Clear all' after session timeout; backend refusing the wipe because the key store is locked or read-only (mounted volume permissions in Docker).
Related errors
- Failed to load API key status (status ${res.status}).
- ${data.detail || Failed to update API keys (status ${res.sta
- ${data.detail || Failed to delete API key (status ${res.stat
- ${data.detail || Failed to reset database (status ${res.stat
- Failed to load prompt config (status ${res.status}).
AI-assisted analysis of srbhr/Resume-Matcher@116f9cc3b0 (2026-08-28).
Data as JSON: /api/errors/caf202dbd972a164.
Report an issue: GitHub.