{"record":{"id":"421c0e94ee780540","repo":"janhq/jan","slug":"unexpected-error-while-fetching-models-from-prov","errorCode":null,"errorMessage":"Unexpected error while fetching models from ${provider.provider}: ${error instanceof Error ? error.message : 'Unknown error'}","messagePattern":"Unexpected error while fetching models from (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"web-app/src/services/providers/tauri.ts","lineNumber":278,"sourceCode":"\n      if (\n        error instanceof Error &&\n        structuredErrorPrefixes.some((prefix) =>\n          (error as Error).message.startsWith(prefix)\n        )\n      ) {\n        throw new Error(error.message)\n      }\n\n      // Provide helpful error message for any connection errors\n      if (error instanceof Error && error.message.includes('fetch')) {\n        throw new Error(\n          `Cannot connect to ${provider.provider} at ${provider.base_url}. Please check that the service is running and accessible.`\n        )\n      }\n\n      // Generic fallback\n      throw new Error(\n        `Unexpected error while fetching models from ${provider.provider}: ${error instanceof Error ? error.message : 'Unknown error'}`\n      )\n    }\n  }\n\n  async updateSettings(\n    providerName: string,\n    settings: ProviderSetting[]\n  ): Promise<void> {\n    try {\n      // API keys are persisted to the OS keyring only (via\n      // register_provider_config), never to the extension's settings.json.\n      // Blank the key entries at this single chokepoint regardless of caller.\n      const isSecretKey = (key: string) =>\n        key === 'api-key' || key === API_KEY_FALLBACKS_SETTING_KEY\n      return ExtensionManager.getInstance()\n        .getEngine(providerName)\n        ?.updateSettings(","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/web-app/src/services/providers/tauri.ts#L260-L296","documentation":"Generic fallback thrown when fetchModelsFromProvider catches an error that is neither a structured HTTP error nor a fetch/connectivity failure — e.g. response.json() throwing on invalid JSON, an unexpected TypeError, or a non-Error value thrown. The original message is embedded for diagnosis.","triggerScenarios":"response.json() fails because the endpoint returned HTML or invalid JSON; an unexpected runtime TypeError during parsing; a non-Error thrown from fetchTauri whose message lacks 'fetch'.","commonSituations":"Server returns an HTML error page or empty body with 200; a proxy intercepts the response; a bug in response parsing for a provider with an unusual schema; older server versions returning malformed payloads.","solutions":["Inspect the embedded inner message to identify the original failure.","curl the /models endpoint and check whether it returns valid JSON (not HTML).","Fix the proxy/server so a 200 response carries a JSON body.","Update the local server/provider config to a compatible API version."],"exampleFix":"// before: proxy returns HTML 200 page for /models\n// after: exclude /models from the catch-all proxy route\nlocation /v1/ { proxy_pass http://backend; }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function looksLikeJsonResponse(ct: string | null): boolean {\n  return !!ct && ct.includes('application/json')\n}","tryCatchPattern":"try {\n  await fetchModelsFromProvider(provider)\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Unexpected error while fetching models')) {\n    logInnerCause(e.message); suggestServerFix(provider.provider)\n  }\n}","preventionTips":["Verify the endpoint returns JSON (Content-Type and body) with curl.","Ensure proxies don't replace API responses with HTML pages.","Keep local inference servers updated to API-compatible versions."],"tags":["json","unexpected-error","provider-api","parsing"],"backgroundTag":"json-parse-error","analyzedSha":"7205d770c1e097c3daf35a911176410e93bc5564","analyzedAt":"2026-09-17T14:27:30.100Z","contentChangedAt":"2026-09-17T14:27:30.100Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}