{"record":{"id":"512165ec94381813","repo":"different-ai/openwork","slug":"the-dashboard-response-was-invalid","errorCode":null,"errorMessage":"The dashboard response was invalid.","messagePattern":"The dashboard response was invalid\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/org-dashboards-data.tsx","lineNumber":207,"sourceCode":"}\n\nexport function useManagedDashboard(dashboardId: string) {\n  const { orgContext } = useOrgDashboard();\n  const organizationId = orgContext?.organization.id ?? \"\";\n  return useQuery({\n    enabled: Boolean(organizationId && dashboardId),\n    queryKey: orgDashboardsQueryKeys.detail(organizationId, dashboardId),\n    queryFn: async (): Promise<ManagedDashboard> => {\n      const { response, payload } = await requestJson(\n        `/v1/dashboards/${encodeURIComponent(dashboardId)}`,\n        { method: \"GET\" },\n        15000,\n      );\n      if (!response.ok) {\n        throw new Error(getErrorMessage(payload, `Failed to load the dashboard (${response.status}).`));\n      }\n      const item = isRecord(payload) ? parseDashboard(payload.item) : null;\n      if (!item) throw new Error(\"The dashboard response was invalid.\");\n      return item;\n    },\n  });\n}\n\nexport function useCreateDashboard() {\n  const queryClient = useQueryClient();\n  const { orgContext, runReauthableAction } = useOrgDashboard();\n  const organizationId = orgContext?.organization.id ?? \"\";\n  return useMutation({\n    mutationFn: async (input: { name: string }): Promise<ManagedDashboard> => {\n      let created: ManagedDashboard | null = null;\n      await runReauthableAction(\"create-dashboard\", async () => {\n        const { response, payload } = await requestJson(\n          \"/v1/dashboards\",\n          { method: \"POST\", body: JSON.stringify({ name: input.name }) },\n          15000,\n        );","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/org-dashboards-data.tsx#L189-L225","documentation":"After a successful (ok) response, useManagedDashboard runs payload.item through parseDashboard; if the body is not an object or parseDashboard cannot build a valid ManagedDashboard, this error is thrown. It guards against a 200 response whose body violates the expected dashboard schema.","triggerScenarios":"Server returned 200 with `{ item: null }`, an empty body, an unexpected field layout (renamed fields after an API change), or parseDashboard's required fields (e.g. id/name) missing or of the wrong type.","commonSituations":"Frontend/server version skew after a den-api deploy; CDN or service worker serving a cached/other response body; a test/stub server returning a placeholder payload.","solutions":["Log the raw payload and compare against the current parseDashboard field expectations","Align frontend and den-api versions — a schema migration likely renamed or removed fields","Hard-refresh / clear cache to rule out a stale service-worker or CDN response","Add a field-by-field check for which required field parseDashboard rejected"],"exampleFix":"// before\nconst item = isRecord(payload) ? parseDashboard(payload.item) : null;\nif (!item) throw new Error(\"The dashboard response was invalid.\");\n// after\nconst item = isRecord(payload) ? parseDashboard(payload.item) : null;\nif (!item) {\n  console.error('dashboard payload failed parseDashboard', payload);\n  throw new Error(\"The dashboard response was invalid.\");\n}","handlingStrategy":"validation","validationCode":"function looksLikeDashboard(payload: unknown): boolean {\n  return isRecord(payload) && isRecord(payload.item) && typeof payload.item.id === 'string' && typeof payload.item.name === 'string';\n}\n// check before trusting data from the query","typeGuard":"const isDashboardItem = (p: unknown): p is { item: Record<string, unknown> } =>\n  isRecord(p) && isRecord(p.item) && typeof (p.item as { id?: unknown }).id === 'string';","tryCatchPattern":"const { data, error } = useManagedDashboard(dashboardId);\nif (error instanceof Error && error.message === 'The dashboard response was invalid.') {\n  logSchemaMismatch('managed-dashboard', dashboardId);\n  showFatalDataError();\n}","preventionTips":["Log the offending payload whenever parseDashboard returns null","Add schema/contract tests covering the GET /v1/dashboards/:id response","Deploy web and API together when dashboard fields change","Treat query data as unknown until parsed — never cast the raw payload"],"tags":["schema-validation","api-response","react-query"],"backgroundTag":"schema-validation-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}