srbhr/Resume-Matcher · error · Error

Failed to test LLM connection (status ${res.status}).

Error message

Failed to test LLM connection (status ${res.status}).

What it means

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.

Source

Thrown at apps/frontend/lib/api/config.ts:134

}

// Test LLM connection with optional config (for pre-save testing)
export async function testLlmConnection(config?: LLMConfigUpdate): Promise<LLMHealthCheck> {
  const options: RequestInit = {
    method: 'POST',
    credentials: 'include',
  };

  // If config provided, send it in the request body
  if (config) {
    options.headers = { 'Content-Type': 'application/json' };
    options.body = JSON.stringify(config);
  }

  const res = await apiFetch('/config/llm-test', options);

  if (!res.ok) {
    throw new Error(`Failed to test LLM connection (status ${res.status}).`);
  }

  return res.json();
}

// Fetch system status
export async function fetchSystemStatus(): Promise<SystemStatus> {
  const res = await apiFetch('/status', { credentials: 'include' });

  if (!res.ok) {
    throw new Error(`Failed to fetch system status (status ${res.status}).`);
  }

  return res.json();
}

// Provider display names and default models
export const PROVIDER_INFO: Record<

View on GitHub (pinned to 116f9cc3b0)

Solutions

  1. Confirm the API key and provider/base URL in the form are correct, then retry the test
  2. Check backend logs for the upstream provider error (DNS, proxy, 401 from provider) if status is 5xx
  3. Re-authenticate if status is 401/403
  4. Verify the backend deployment includes the /config/llm-test route (404)

Example fix

// before
await testLlmConnection(cfg); // unhandled throw on failure
// after
const res = await testLlmConnection(cfg).catch((e) => ({ ok: false, error: e.message }));
if (!res.ok) showMsg(`LLM test failed: ${res.error}`);
Defensive patterns

Strategy: try-catch

Validate before calling

function canTest(cfg: LLMConfig): boolean {
  return Boolean(cfg.provider && cfg.model && cfg.apiKey);
}
if (!canTest(cfg)) showMsg('Fill provider, model and API key before testing');

Type guard

function isTestFailure(e: unknown): e is Error & { status?: number } {
  const m = e instanceof Error ? e.message.match(/status (\d{3})/) : null;
  if (e instanceof Error && m) (e as any).status = Number(m[1]);
  return e instanceof Error;
}

Try / catch

try {
  result = await testLlmConnection(cfg);
} catch (e) {
  const s = (e as any)?.status;
  showMsg(s >= 500 ? 'Backend could not reach the LLM provider' : `Test failed: ${e.message}`);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of srbhr/Resume-Matcher@116f9cc3b0 (2026-08-28). Data as JSON: /api/errors/97fcc3c1ddbed26c. Report an issue: GitHub.