different-ai/openwork · error

Failed to create organization.

Error message

Failed to create organization.

What it means

organization-screen.tsx throws this as the fallback message when `POST /v1/org` returns a non-ok status without a parseable error payload. The organization was not created, but the API gave no specific reason.

Source

Thrown at ee/apps/den-web/app/(den)/_components/organization-screen.tsx:114

    e.preventDefault();
    if (isSingleOrgMode) {
      setCreateError("This deployment uses one managed organization.");
      return;
    }

    const trimmed = createName.trim();
    if (!trimmed) return;

    setCreateBusy(true);
    setCreateError(null);
    try {
      const { response, payload } = await requestJson("/v1/org", {
        method: "POST",
        body: JSON.stringify({ name: trimmed }),
      });

      if (!response.ok) {
        throw new Error(getErrorMessage(payload, "Failed to create organization."));
      }

      const organization =
        typeof payload === "object" && payload && "organization" in payload && payload.organization && typeof payload.organization === "object"
          ? (payload.organization as { slug?: unknown })
          : null;
      const nextSlug = typeof organization?.slug === "string" ? organization.slug : null;

      if (!nextSlug) {
        throw new Error("Organization was created, but no slug was returned.");
      }

      const pendingIntent = normalizeAuthIntentParam(window.sessionStorage.getItem(PENDING_AUTH_INTENT_STORAGE_KEY));
      if (pendingIntent === "models") {
        window.sessionStorage.removeItem(PENDING_AUTH_INTENT_STORAGE_KEY);
        router.push(getInferenceRoute(nextSlug));
        return;
      }

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Check the response status code in the network tab to identify the real cause
  2. Retry with a different organization name if it is a duplicate (409)
  3. Re-authenticate if the status is 401
  4. Have the API return a JSON error body so getErrorMessage can surface the server's message
Defensive patterns

Strategy: validation

Validate before calling

const name = trimmed;
if (!name || name.length > 64) {
  setError("Organization name must be 1-64 characters.");
  return;
}

Type guard

function isOrgPayload(p: unknown): p is { organization: { slug: string } } {
  return typeof p === "object" && p !== null && "organization" in p && typeof (p as { organization: unknown }).organization === "object";
}

Try / catch

try {
  const { response, payload } = await requestJson("/v1/org", { method: "POST", body: JSON.stringify({ name }) });
  if (!response.ok) throw new Error(getErrorMessage(payload, "Failed to create organization."));
} catch (err) {
  if (isDuplicateOrgError(err)) setError("That organization name is taken. Try another.");
  else setError("Failed to create organization. Please try again.");
}

Prevention

When it happens

Trigger: `requestJson("/v1/org", { method: "POST", body: ... })` responds with response.ok === false and no message in the payload — e.g. 409 duplicate name, 401 unauthorized, or 422 validation failure with empty body.

Common situations: User submits an org name that already exists (409); session expired mid-flow (401); server-side validation rejects the name with a non-JSON body; rate limiting (429) with empty response.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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