{"record":{"id":"013fd2f22d1a3425","repo":"diegosouzapw/OmniRoute","slug":"openroutercatalog-fetch-failed-using-stale-cach","errorCode":null,"errorMessage":"[OpenRouterCatalog] Fetch failed, using stale cache:","messagePattern":"\\[OpenRouterCatalog\\] Fetch failed, using stale cache:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/catalog/openrouterCatalog.ts","lineNumber":144,"sourceCode":"  if (cache && cache.fetchedAt) {\n    const age = now - new Date(cache.fetchedAt).getTime();\n    if (age < ttl) {\n      return {\n        data: cache.data,\n        stale: false,\n        cachedAt: cache.fetchedAt,\n        fromCache: true,\n      };\n    }\n  }\n\n  // Cache expired or missing — attempt fresh fetch\n  try {\n    const data = await fetchFromAPI();\n    writeCache(data);\n    return { data, stale: false, cachedAt: null, fromCache: false };\n  } catch (err) {\n    console.warn(\"[OpenRouterCatalog] Fetch failed, using stale cache:\", err);\n\n    // Stale-if-error: return old cache if available\n    if (cache) {\n      return {\n        data: cache.data,\n        stale: true,\n        cachedAt: cache.fetchedAt,\n        fromCache: true,\n      };\n    }\n\n    // No cache at all — return empty with error signal\n    return { data: [], stale: true, cachedAt: null, fromCache: false };\n  }\n}\n\n/**\n * Force-refresh the catalog cache (ignores TTL).","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/catalog/openrouterCatalog.ts#L126-L162","documentation":"OpenRouterCatalog stale-if-error path: the fresh fetchFromAPI() threw (network/upstream) after the cache TTL expired, so the code falls back to serving the stale cached catalog if one exists — degraded freshness, not an outright failure.","triggerScenarios":"Thrown at src/lib/catalog/openrouterCatalog.ts:144 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Restore outbound access to OpenRouter","Accept stale data temporarily — it self-heals on next successful fetch","Clear the cache file if corruption is suspected"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}