different-ai/openwork · error · Error

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

Error message

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

What it means

Thrown by useCreateMarketplace when the POST that creates a collection (marketplace) returns a non-ok HTTP status. getRequestError extracts the server's error message from the JSON payload, falling back to 'Failed to create collection (<status>)'. It indicates the server refused collection creation before any response parsing could occur.

Source

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

  const { runReauthableAction } = useOrgDashboard();

  return useMutation({
    mutationFn: async (input: { name: string; description?: string }): Promise<DenMarketplace> => {
      let created: DenMarketplace | null = null;
      await runReauthableAction("create-marketplace", async () => {
        const { response, payload } = await requestJson(
          "/v1/marketplaces",
          {
            method: "POST",
            body: JSON.stringify({
              name: input.name,
              ...(input.description ? { description: input.description } : {}),
            }),
          },
          15000,
        );
        if (!response.ok) {
          throw getRequestError(payload, response, `Failed to create collection (${response.status}).`);
        }
        created = isRecord(payload) && isRecord(payload.item) ? parseMarketplace(payload.item) : null;
      });
      if (!created) {
        throw new Error("Collection create response was incomplete.");
      }
      return created;
    },
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: marketplaceQueryKeys.all });
    },
  });
}

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

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Check the status in the message: for 401/403, re-authenticate or obtain marketplace-create permission for the org.
  2. For 400/409/422, fix the submitted name/description (uniqueness, length) and resubmit.
  3. For 5xx, retry with backoff and check Den server health.
  4. Surface isReauthRequiredError to trigger the re-auth flow rather than a generic toast.

Example fix

// before
await createMutation.mutateAsync({ name });
// after
try {
  await createMutation.mutateAsync({ name });
} catch (err) {
  if (isReauthRequiredError(err)) { startReauth(); }
  else setCreateError(err.message);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before createMutation.mutateAsync
const name = input.name?.trim();
if (!name) throw new Error("Collection name is required");
if (name.length > 120) throw new Error("Collection name is too long");
if (existingNames.has(name)) throw new Error("A collection with this name already exists");

Type guard

function isReauthError(err: unknown): err is ReauthRequiredError {
  return err instanceof ReauthRequiredError;
}

Try / catch

try {
  await createMutation.mutateAsync(input);
} catch (err) {
  if (isReauthRequiredError(err)) startReauth();
  else setFormError(err.message);
}

Prevention

When it happens

Trigger: Non-ok response from POST /v1/marketplaces (15000ms timeout): 401 when not signed in, 403 when the user lacks marketplace-create permission in the org, 400/422 when name/description violate server validation (duplicate name, length limits), 409 on name conflicts, 5xx on server faults.

Common situations: User session expired; org role downgraded so creating collections is forbidden; duplicate collection name; oversized description; Den server errors during deployments.

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/fb2564a3c0d20e29. Report an issue: GitHub.