different-ai/openwork · error

Failed to delete the dashboard (${response.status}).

Error message

Failed to delete the dashboard (${response.status}).

What it means

Thrown in useDeleteDashboard's mutation when DELETE /v1/dashboards/:id returns neither 204 nor a generic ok status. The 204 carve-out means a body-less success is accepted; anything else non-ok (404, 403, 500...) raises this error with the status embedded in the fallback message.

Source

Thrown at ee/apps/den-web/app/(den)/dashboard/_components/org-dashboards-data.tsx:284

      queryClient.invalidateQueries({ queryKey: orgDashboardsQueryKeys.detail(organizationId, dashboardId) });
    },
  });
}

export function useDeleteDashboard() {
  const queryClient = useQueryClient();
  const { orgContext, runReauthableAction } = useOrgDashboard();
  const organizationId = orgContext?.organization.id ?? "";
  return useMutation({
    mutationFn: async (input: { dashboardId: string }) => {
      await runReauthableAction("delete-dashboard", async () => {
        const { response, payload } = await requestJson(
          `/v1/dashboards/${encodeURIComponent(input.dashboardId)}`,
          { method: "DELETE" },
          15000,
        );
        if (response.status !== 204 && !response.ok) {
          throw getRequestError(payload, response, `Failed to delete the dashboard (${response.status}).`);
        }
      });
    },
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: orgDashboardsQueryKeys.list(organizationId) });
    },
  });
}

export function useDashboardAccess(dashboardId: string) {
  const { orgContext } = useOrgDashboard();
  const organizationId = orgContext?.organization.id ?? "";
  return useQuery({
    enabled: Boolean(organizationId && dashboardId),
    queryKey: orgDashboardsQueryKeys.access(organizationId, dashboardId),
    queryFn: async (): Promise<DashboardAccessGrant[]> => {
      const { response, payload } = await requestJson(
        `/v1/dashboards/${encodeURIComponent(dashboardId)}/access`,

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. On 404, refresh the dashboard list — the dashboard is already gone; treat as success for the user.
  2. On 401/403, re-authenticate or verify org permissions (handle ReauthRequiredError via isReauthRequiredError).
  3. On 5xx, retry after the server recovers; check whether the deletion actually landed before retrying to avoid double-delete confusion.
  4. Ensure dashboardId is passed through encodeURIComponent (it is here) and is a valid ID.

Example fix

// before
if (response.status !== 204 && !response.ok) {
  throw getRequestError(payload, response, `Failed to delete the dashboard (${response.status}).`);
}
// after
if (response.status === 404) return; // already deleted concurrently
if (response.status !== 204 && !response.ok) {
  throw getRequestError(payload, response, `Failed to delete the dashboard (${response.status}).`);
}
Defensive patterns

Strategy: retry

Validate before calling

if (!input.dashboardId || typeof input.dashboardId !== "string") {
  throw new Error("A valid dashboardId is required to delete a dashboard.");
}

Type guard

function isDashboardId(value: unknown): value is string {
  return typeof value === "string" && value.length > 0;
}

Try / catch

try {
  await deleteDashboard.mutateAsync({ dashboardId });
} catch (error) {
  if (isReauthRequiredError(error)) return startReauth();
  if (error.message.includes("(404)")) return; // already deleted; refetch list
  toast.error(error.message);
} finally {
  await queryClient.invalidateQueries({ queryKey: orgDashboardsQueryKeys.list(organizationId) });
}

Prevention

When it happens

Trigger: Deleting a dashboard that no longer exists (404, e.g. deleted concurrently), lacking delete permission (403), expired session (401), or a server error during cascade deletion of dashboard elements.

Common situations: Clicking delete on a stale list after another admin removed the dashboard; role revoked mid-session; backend failure while removing associated grants/elements.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/7d9679c101c58dd7. Report an issue: GitHub.