{"record":{"id":"f279ce9beb027bae","repo":"janhq/jan","slug":"failed-to-fetch-model-catalog-error-instanceof","errorCode":null,"errorMessage":"Failed to fetch model catalog: ${error instanceof Error ? error.message : 'Unknown error'}","messagePattern":"Failed to fetch model catalog: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"web-app/src/services/models/default.ts","lineNumber":74,"sourceCode":"  async fetchModels(): Promise<modelInfo[]> {\n    return this.getEngine()?.list() ?? []\n  }\n\n  async fetchModelCatalog(): Promise<ModelCatalog> {\n    try {\n      const response = await fetch(MODEL_CATALOG_URL)\n\n      if (!response.ok) {\n        throw new Error(\n          `Failed to fetch model catalog: ${response.status} ${response.statusText}`\n        )\n      }\n\n      const catalog: ModelCatalog = await response.json()\n      return catalog\n    } catch (error) {\n      console.error('Error fetching model catalog:', error)\n      throw new Error(\n        `Failed to fetch model catalog: ${error instanceof Error ? error.message : 'Unknown error'}`\n      )\n    }\n  }\n\n  async fetchLatestJanModel(): Promise<CatalogModel | null> {\n    try {\n      const response = await fetch(LATEST_JAN_MODEL_URL)\n\n      if (!response.ok) {\n        console.error(\n          `Failed to fetch latest Jan model: ${response.status} ${response.statusText}`\n        )\n        return null\n      }\n\n      const data = await response.json()\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/web-app/src/services/models/default.ts#L56-L92","documentation":"The catch block of fetchModelCatalog rethrows any failure (network error, JSON parse failure, or the non-OK throw above) as a wrapped 'Failed to fetch model catalog' error. It preserves the original message when the cause is an Error.","triggerScenarios":"fetch() rejects (DNS failure, offline, CORS), response.json() fails on invalid JSON, or the inner non-OK throw is caught and rewrapped.","commonSituations":"No internet connection, catalog server returning malformed JSON, CORS blocking the request in the webview, or certificate errors.","solutions":["Check internet connectivity and retry","Inspect the wrapped inner message for the root cause (network vs JSON)","Validate the catalog endpoint returns valid JSON","Add a timeout and offline fallback catalog"],"exampleFix":"// before\nthrow new Error(`Failed to fetch model catalog: ${error instanceof Error ? error.message : 'Unknown error'}`)\n// after\nif (error instanceof TypeError) throw new Error('Network unavailable: could not fetch model catalog')\nthrow new Error(`Failed to fetch model catalog: ${error instanceof Error ? error.message : 'Unknown error'}`)","handlingStrategy":"retry","validationCode":"if (!navigator.onLine) throw new Error('Offline: model catalog unavailable')","typeGuard":"null","tryCatchPattern":"try { catalog = await fetchModelCatalog() } catch (e) { log.warn(e); catalog = await loadCachedCatalog() }","preventionTips":["Add fetch timeouts and exponential-backoff retries","Check navigator.onLine before network calls","Cache last-good catalog responses"],"tags":["network","fetch","json"],"backgroundTag":"network-request-failed","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"}