{"record":{"id":"a511e9d09694d517","repo":"different-ai/openwork","slug":"endpoint-test-returned-an-unexpected-response","errorCode":null,"errorMessage":"Endpoint test returned an unexpected response.","messagePattern":"Endpoint test returned an unexpected response\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/llm-provider-data.tsx","lineNumber":455,"sourceCode":" * mistakes and returns the model ids the endpoint actually serves.\n */\nexport async function requestLlmProviderTestConnection(input: {\n  api: string;\n  apiKey?: string;\n  modelIds?: string[];\n}) {\n  const timeoutMs = input.modelIds?.length ? 60000 : 20000;\n  const { response, payload } = await requestJson(\n    `/v1/llm-providers/test-connection`,\n    { method: \"POST\", body: JSON.stringify(input) },\n    timeoutMs,\n  );\n  if (!response.ok) {\n    throw new Error(getErrorMessage(payload, `Endpoint test failed (${response.status}).`));\n  }\n  const result = isRecord(payload) ? asProbeResult(payload.result) : null;\n  if (!result) {\n    throw new Error(\"Endpoint test returned an unexpected response.\");\n  }\n  const verifications = isRecord(payload) && Array.isArray(payload.verifications)\n    ? payload.verifications\n        .map(asModelVerification)\n        .filter((entry): entry is LlmProviderModelVerification => entry !== null)\n    : [];\n  return { ...result, verifications };\n}\n\nexport async function requestLlmProviderCatalog(orgId: string) {\n  const { response, payload } = await requestJson(`/v1/llm-provider-catalog`, { method: \"GET\" }, 20000);\n  if (!response.ok) {\n    throw new Error(getErrorMessage(payload, `Failed to load the provider catalog (${response.status}).`));\n  }\n\n  return isRecord(payload) && Array.isArray(payload.providers)\n    ? payload.providers.map(asCatalogProviderSummary).filter((entry): entry is DenModelsDevProviderSummary => entry !== null)\n    : [];","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/llm-provider-data.tsx#L437-L473","documentation":"After a successful (2xx) POST to /v1/llm-providers/test-connection, the function expects payload.result to be a valid probe result; if asProbeResult cannot coerce payload.result, the 200 response is considered malformed and this error is thrown. It protects callers from trusting an unparseable probe result.","triggerScenarios":"The test-connection endpoint returns 200 with a body whose `result` field is missing, null, or shaped differently than asProbeResult expects (e.g. newer server fields, changed nesting, plain string instead of object).","commonSituations":"Frontend and backend version skew after an API change to the probe result schema; a middleware/proxy transforming the JSON; a mock or test server returning a partial body; server bug returning `{}` on success.","solutions":["Log the raw payload and compare its `result` shape against the LlmProviderProbeResult type / asProbeResult expectations.","Update asProbeResult to match the server's current result schema.","Align frontend and backend deployments so both use the same API version.","Fix the server handler if it returns 200 without a valid result on probe failure (it should return non-ok or a well-formed result)."],"exampleFix":"// before (server returns result without ok flag)\nreturn NextResponse.json({ result: { latencyMs: 120 } });\n// after\nreturn NextResponse.json({ result: { ok: true, latencyMs: 120 } });","handlingStrategy":"type-guard","validationCode":"// after receiving a 2xx, guard before use\nfunction looksLikeProbeResult(p: unknown): boolean {\n  return typeof p === \"object\" && p !== null && typeof (p as {result?:unknown}).result === \"object\" && (p as {result?:unknown}).result !== null;\n}","typeGuard":"function isProbeResult(v: unknown): v is LlmProviderProbeResult {\n  return typeof v === \"object\" && v !== null && \"ok\" in v && typeof (v as {ok:unknown}).ok === \"boolean\";\n}","tryCatchPattern":"try {\n  const result = await requestLlmProviderTestConnection(input, timeoutMs);\n} catch (err) {\n  if (err instanceof Error && err.message === \"Endpoint test returned an unexpected response.\") {\n    console.error(\"test-connection 200 body malformed — check server/client versions\");\n  } else throw err;\n}","preventionTips":["Add a shared zod/valibot schema for the probe result used by both server and client.","Test the endpoint against a contract fixture in CI.","Avoid returning bare 200s on probe failure; use non-ok or a well-formed result.","Keep den-web and den-api deployed in lockstep for this endpoint."],"tags":["schema-validation","api-contract","llm-provider","den-web"],"backgroundTag":"api-response-schema-mismatch","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}