different-ai/openwork · error · Error

Failed to delete collection (${response.status}).

Error message

Failed to delete collection (${response.status}).

What it means

Thrown by useDeleteMarketplace when POST /v1/marketplaces/:id/delete returns a non-ok status. getRequestError substitutes the server's error message or the fallback 'Failed to delete collection (<status>)'. The query's onSuccess cleanup (removeQueries) never runs because the throw happens first, so cached data stays as-is.

Source

Thrown at ee/apps/den-web/app/(den)/dashboard/_components/marketplace-data.tsx:508

      queryClient.invalidateQueries({ queryKey: marketplaceQueryKeys.resolved(marketplace.id) });
    },
  });
}

export function useDeleteMarketplace() {
  const queryClient = useQueryClient();
  const { runReauthableAction } = useOrgDashboard();

  return useMutation({
    mutationFn: async (marketplaceId: string): Promise<string> => {
      await runReauthableAction("delete-marketplace", async () => {
        const { response, payload } = await requestJson(
          `/v1/marketplaces/${encodeURIComponent(marketplaceId)}/delete`,
          { method: "POST" },
          15000,
        );
        if (!response.ok) {
          throw getRequestError(payload, response, `Failed to delete collection (${response.status}).`);
        }
      });
      return marketplaceId;
    },
    onSuccess: (marketplaceId) => {
      queryClient.removeQueries({ queryKey: marketplaceQueryKeys.resolved(marketplaceId) });
      queryClient.invalidateQueries({ queryKey: marketplaceQueryKeys.list() });
    },
  });
}

export function formatMarketplaceTimestamp(value: string | null): string {
  if (!value) return "Recently added";
  const date = new Date(value);
  if (Number.isNaN(date.getTime())) return "Recently added";
  return new Intl.DateTimeFormat("en-US", {
    month: "short",
    day: "numeric",

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. For 403, confirm the user has owner/admin rights on the collection before deleting.
  2. For 404, treat as already-deleted: invalidate/remove the marketplace queries and refresh the UI.
  3. For 409, remove or reassign dependent resources (published plugins) and retry.
  4. For 401, re-authenticate; for 5xx, retry with backoff and check Den server health.
  5. Check isReauthRequiredError to trigger the re-auth flow.

Example fix

// before
await deleteMarketplace(id);
// after
try {
  await deleteMarketplace(id);
} catch (err) {
  if (isReauthRequiredError(err)) { startReauth(); }
  else if (/\(404\)/.test(err.message)) { queryClient.removeQueries({ queryKey: marketplaceQueryKeys.resolved(id) }); }
  else setDeleteError(err.message);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before deleteMarketplace
if (!marketplaceId) throw new Error("Missing collection id");
if (!canManage(marketplace)) throw new Error("You do not have permission to delete this collection");

Type guard

function isAlreadyDeleted(err: unknown): boolean {
  return err instanceof Error && /\(404\)/.test(err.message);
}

Try / catch

try {
  await deleteMarketplace(id);
} catch (err) {
  if (isReauthRequiredError(err)) startReauth();
  else if (isAlreadyDeleted(err)) { queryClient.removeQueries({ queryKey: marketplaceQueryKeys.resolved(id) }); }
  else showError(err.message);
}

Prevention

When it happens

Trigger: Non-ok response from the delete endpoint (15000ms timeout): 403 when the caller is not an owner/admin of the collection, 404 when it was already deleted, 409 when the server refuses deletion (e.g., plugins still published), 401 for expired sessions, 5xx for server faults.

Common situations: Trying to delete a shared/org collection without owner rights; double-click delete causing the second 404; server-side referential-integrity rules blocking deletion; expired Den session.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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