{"record":{"id":"9e31a14998758ad0","repo":"Egonex-AI/Understand-Anything","slug":"http-res-status","errorCode":null,"errorMessage":"HTTP ${res.status}","messagePattern":"HTTP \\$\\{res\\.status\\}","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"understand-anything-plugin/packages/dashboard/src/App.tsx","lineNumber":162,"sourceCode":"  useEffect(() => {\n    fetch(dataUrl(\"knowledge-graph.json\", accessToken))\n      .then(async (res) => {\n        // Guard res.ok before parsing (matching the meta.json/config.json/\n        // diff-overlay.json/domain-graph.json fetches in this file). Without\n        // this, a serving/config failure returns a 404 JSON error body that\n        // gets parsed and handed to validateGraph, which fails project-metadata\n        // validation and surfaces the misleading \"Invalid knowledge graph:\n        // Missing or invalid project metadata\" instead of the real cause\n        // (graph file not found / GRAPH_DIR unset). See issues #288, #406.\n        if (!res.ok) {\n          let detail = `HTTP ${res.status}`;\n          try {\n            const body = await res.json();\n            if (body?.error) detail = body.error;\n          } catch {\n            /* non-JSON error body; keep the status code */\n          }\n          throw new Error(detail);\n        }\n        return res.json();\n      })\n      .then((data: unknown) => {\n        const result = validateGraph(data);\n        if (result.success && result.data) {\n          setGraph(result.data);\n          setGraphIssues(result.issues);\n          if ((data as Record<string, unknown>).kind === \"knowledge\") {\n            useDashboardStore.getState().setViewMode(\"knowledge\");\n            useDashboardStore.getState().setIsKnowledgeGraph(true);\n          }\n          for (const issue of result.issues) {\n            if (issue.level === \"auto-corrected\") {\n              console.warn(`[graph] auto-corrected: ${issue.message}`);\n            } else if (issue.level === \"dropped\") {\n              console.error(`[graph] dropped: ${issue.message}`);\n            }","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/Egonex-AI/Understand-Anything/blob/32944829e7a63a9fa9c55d811d7f98a9530c6a6a/understand-anything-plugin/packages/dashboard/src/App.tsx#L144-L180","documentation":"Thrown by the dashboard's knowledge-graph loader in App.tsx when fetch(dataUrl('knowledge-graph.json', accessToken)) returns a non-ok response. The guard runs before res.json() so that a 404/500 JSON error body is not silently fed into validateGraph (which would otherwise surface the misleading 'Invalid knowledge graph: Missing or invalid project metadata'). It prefers body.error when the server provides one, falling back to `HTTP <status>`.","triggerScenarios":"The dev server returns non-200 for knowledge-graph.json: GRAPH_DIR env unset or pointing at a missing directory (404), the access token is wrong/missing (403), the server is misconfigured (500), or the graph file genuinely does not exist yet because /understand has not been run in the target project.","commonSituations":"Starting the dashboard before running /understand (no graph generated). GRAPH_DIR not exported in the dev-server environment. Wrong UA_DASHBOARD_ACCESS_TOKEN in the browser vs server. Serving from a different working directory than expected. Reverse proxy / CORS intercepting the request. The graph was moved/deleted out from under the server.","solutions":["Run /understand (or /understand --full) in the target project so knowledge-graph.json is generated in its .ua/ directory.","Confirm GRAPH_DIR is set for the dev server process and points at the project's .ua/ (or legacy .understand-anything/) directory.","Verify the access token in the browser URL/header matches UA_DASHBOARD_ACCESS_TOKEN on the server.","Open the failing URL directly in the browser to read the server's JSON error body, which often names the missing file or directory.","Check the dev server console for the stack trace that produced the non-200 response."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before mounting the dashboard, ensure the graph exists\nimport { existsSync, statSync } from 'node:fs';\nfunction ensureGraphServed(graphDir) {\n  if (!graphDir) throw new Error('GRAPH_DIR env is unset');\n  const p = `${graphDir}/knowledge-graph.json`;\n  if (!existsSync(p) || !statSync(p).isFile()) {\n    throw new Error(`knowledge-graph.json not found at ${p}; run /understand first`);\n  }\n}","typeGuard":null,"tryCatchPattern":"// in the dashboard fetch chain (matches App.tsx pattern)\nfetch(dataUrl('knowledge-graph.json', accessToken))\n  .then(async (res) => {\n    if (!res.ok) {\n      let detail = `HTTP ${res.status}`;\n      try { const b = await res.json(); if (b?.error) detail = b.error; } catch {}\n      throw new Error(detail);\n    }\n    return res.json();\n  })\n  .catch((err) => setLoadError(`Failed to load knowledge graph: ${err.message}`));","preventionTips":["Run /understand before starting the dashboard so knowledge-graph.json exists.","Set GRAPH_DIR for the dev server to the project's .ua/ directory.","Keep the access token consistent between server (UA_DASHBOARD_ACCESS_TOKEN) and browser.","Open the failing URL directly to read the server's JSON error body."],"tags":["dashboard","network","fetch","knowledge-graph","configuration"],"backgroundTag":null,"analyzedSha":"32944829e7a63a9fa9c55d811d7f98a9530c6a6a","analyzedAt":"2026-08-12T10:25:44.261Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}