{"record":{"id":"8ba607d9939b0fda","repo":"different-ai/openwork","slug":"failed-to-update-the-dashboard-response-status","errorCode":null,"errorMessage":"Failed to update the dashboard (${response.status}).","messagePattern":"Failed to update the dashboard \\((.+?)\\)\\.","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/org-dashboards-data.tsx","lineNumber":259,"sourceCode":"  const queryClient = useQueryClient();\n  const { orgContext, runReauthableAction } = useOrgDashboard();\n  const organizationId = orgContext?.organization.id ?? \"\";\n  return useMutation({\n    mutationFn: async (input: { dashboardId: string; name?: string; elements?: DashboardElement[] }) => {\n      await runReauthableAction(\"update-dashboard\", async () => {\n        const { response, payload } = await requestJson(\n          `/v1/dashboards/${encodeURIComponent(input.dashboardId)}`,\n          {\n            method: \"PATCH\",\n            body: JSON.stringify({\n              ...(input.name !== undefined ? { name: input.name } : {}),\n              ...(input.elements !== undefined ? { elements: input.elements } : {}),\n            }),\n          },\n          15000,\n        );\n        if (!response.ok) {\n          throw getRequestError(payload, response, `Failed to update the dashboard (${response.status}).`);\n        }\n      });\n      return input.dashboardId;\n    },\n    onSuccess: (dashboardId) => {\n      queryClient.invalidateQueries({ queryKey: orgDashboardsQueryKeys.list(organizationId) });\n      queryClient.invalidateQueries({ queryKey: orgDashboardsQueryKeys.detail(organizationId, dashboardId) });\n    },\n  });\n}\n\nexport function useDeleteDashboard() {\n  const queryClient = useQueryClient();\n  const { orgContext, runReauthableAction } = useOrgDashboard();\n  const organizationId = orgContext?.organization.id ?? \"\";\n  return useMutation({\n    mutationFn: async (input: { dashboardId: string }) => {\n      await runReauthableAction(\"delete-dashboard\", async () => {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/org-dashboards-data.tsx#L241-L277","documentation":"Thrown in useUpdateDashboard's mutation when the PATCH to /v1/dashboards/:id returns non-ok. The fallback message includes the HTTP status; the server's error message takes precedence when present. React Query's updateMutation surfaces it through its error channel.","triggerScenarios":"Updating a dashboard that was deleted by another user (404), renaming to an invalid value (400), token expired (401), insufficient org role (403, possibly ReauthRequiredError), or dashboard ID malformed.","commonSituations":"Two admins editing the same dashboard where one deletes it mid-edit; stale browser tab holding a deleted dashboard; permission downgrades after role changes.","solutions":["Check the status: 404 → refetch the dashboard list (it was deleted); 400 → correct name/elements payload; 401 → re-authenticate; 403 → verify permissions or run reauth.","Invalidate/refetch orgDashboardsQueryKeys.list before retrying so the UI works against current data.","Retry the mutation after refetch; if it was a concurrent delete, discard the local edit.","Confirm the elements payload matches the server schema (only include keys actually changed)."],"exampleFix":"// before\nonError: () => toast.error(\"Update failed\");\n// after\nonError: (error) => {\n  if (isReauthRequiredError(error)) return startReauth();\n  toast.error(error.message);\n  void queryClient.invalidateQueries({ queryKey: orgDashboardsQueryKeys.list(organizationId) });\n}","handlingStrategy":"try-catch","validationCode":"if (!input.dashboardId) throw new Error(\"dashboardId is required.\");\nif (input.name !== undefined && !input.name.trim()) throw new Error(\"Dashboard name cannot be empty.\");","typeGuard":"function isReauthRequiredError(error: unknown): error is ReauthRequiredError {\n  return error instanceof ReauthRequiredError;\n}","tryCatchPattern":"try {\n  await updateDashboard.mutateAsync(input);\n} catch (error) {\n  if (isReauthRequiredError(error)) return startReauth();\n  if (error.message.includes(\"(404)\")) {\n    await queryClient.invalidateQueries({ queryKey: orgDashboardsQueryKeys.list(organizationId) });\n    return toast.error(\"This dashboard no longer exists.\");\n  }\n  toast.error(error.message);\n}","preventionTips":["Refetch the dashboard before applying edits from a long-open editor.","Treat 404 as 'deleted concurrently' and refresh the list rather than retrying blindly.","Include isReauthRequiredError handling in every dashboard mutation onError path.","Only send changed fields in the PATCH payload."],"tags":["http","api","dashboard","react-query","mutation"],"backgroundTag":"http-non-ok-response","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}