{"record":{"id":"97fcc3c1ddbed26c","repo":"srbhr/Resume-Matcher","slug":"failed-to-test-llm-connection-status-res-status","errorCode":null,"errorMessage":"Failed to test LLM connection (status ${res.status}).","messagePattern":"Failed to test LLM connection \\(status (.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/frontend/lib/api/config.ts","lineNumber":134,"sourceCode":"}\n\n// Test LLM connection with optional config (for pre-save testing)\nexport async function testLlmConnection(config?: LLMConfigUpdate): Promise<LLMHealthCheck> {\n  const options: RequestInit = {\n    method: 'POST',\n    credentials: 'include',\n  };\n\n  // If config provided, send it in the request body\n  if (config) {\n    options.headers = { 'Content-Type': 'application/json' };\n    options.body = JSON.stringify(config);\n  }\n\n  const res = await apiFetch('/config/llm-test', options);\n\n  if (!res.ok) {\n    throw new Error(`Failed to test LLM connection (status ${res.status}).`);\n  }\n\n  return res.json();\n}\n\n// Fetch system status\nexport async function fetchSystemStatus(): Promise<SystemStatus> {\n  const res = await apiFetch('/status', { credentials: 'include' });\n\n  if (!res.ok) {\n    throw new Error(`Failed to fetch system status (status ${res.status}).`);\n  }\n\n  return res.json();\n}\n\n// Provider display names and default models\nexport const PROVIDER_INFO: Record<","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/srbhr/Resume-Matcher/blob/116f9cc3b00e1ac91734a6c2679bf41ea64a0edc/apps/frontend/lib/api/config.ts#L116-L152","documentation":"testLlmConnection posts the current LLM config to /config/llm-test and throws this Error when the response is not ok. It exposes only the HTTP status; note that a backend that cannot reach the LLM provider may return 200 with an ok:false payload instead, so this throw means the test endpoint itself failed.","triggerScenarios":"POST /config/llm-test returns non-OK: 401 no session, 422 malformed config payload, 502/504 backend could not reach the LLM provider and surfaces it as a server error, 404 route missing in the deployed backend.","commonSituations":"Clicking 'Test connection' with an invalid API key; backend egress blocked by firewall/proxy so the provider is unreachable; running an older backend without the llm-test route.","solutions":["Confirm the API key and provider/base URL in the form are correct, then retry the test","Check backend logs for the upstream provider error (DNS, proxy, 401 from provider) if status is 5xx","Re-authenticate if status is 401/403","Verify the backend deployment includes the /config/llm-test route (404)"],"exampleFix":"// before\nawait testLlmConnection(cfg); // unhandled throw on failure\n// after\nconst res = await testLlmConnection(cfg).catch((e) => ({ ok: false, error: e.message }));\nif (!res.ok) showMsg(`LLM test failed: ${res.error}`);","handlingStrategy":"try-catch","validationCode":"function canTest(cfg: LLMConfig): boolean {\n  return Boolean(cfg.provider && cfg.model && cfg.apiKey);\n}\nif (!canTest(cfg)) showMsg('Fill provider, model and API key before testing');","typeGuard":"function isTestFailure(e: unknown): e is Error & { status?: number } {\n  const m = e instanceof Error ? e.message.match(/status (\\d{3})/) : null;\n  if (e instanceof Error && m) (e as any).status = Number(m[1]);\n  return e instanceof Error;\n}","tryCatchPattern":"try {\n  result = await testLlmConnection(cfg);\n} catch (e) {\n  const s = (e as any)?.status;\n  showMsg(s >= 500 ? 'Backend could not reach the LLM provider' : `Test failed: ${e.message}`);\n}","preventionTips":["Disable the Test button until required config fields are filled","Check backend egress (DNS/proxy/firewall) to the LLM provider when tests fail with 5xx","Smoke-test the /config/llm-test route after deployments","Distinguish endpoint failure (throw) from provider rejection (ok:false payload) when handling results"],"tags":["http","llm","connectivity","frontend"],"backgroundTag":"http-error-response","analyzedSha":"116f9cc3b00e1ac91734a6c2679bf41ea64a0edc","analyzedAt":"2026-08-28T22:51:40.999Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}