{"record":{"id":"5b824d371fd21503","repo":"different-ai/openwork","slug":"failed-to-create-organization-response-status","errorCode":null,"errorMessage":"Failed to create organization (${response.status}).","messagePattern":"Failed to create organization \\((.+?)\\)\\.","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_providers/org-dashboard-provider.tsx","lineNumber":442,"sourceCode":"    const trimmed = name.trim();\n    if (!trimmed) {\n      throw new Error(\"Enter an organization name.\");\n    }\n\n    setMutationBusy(\"create-organization\");\n    setOrgError(null);\n    try {\n      const { response, payload } = await requestJson(\n        \"/v1/org\",\n        {\n          method: \"POST\",\n          body: JSON.stringify({ name: trimmed }),\n        },\n        12000,\n      );\n\n      if (!response.ok) {\n        throw new Error(getErrorMessage(payload, `Failed to create organization (${response.status}).`));\n      }\n\n      const organization =\n        typeof payload === \"object\" && payload && \"organization\" in payload && payload.organization && typeof payload.organization === \"object\"\n          ? payload.organization as { slug?: unknown }\n          : null;\n      const nextSlug = typeof organization?.slug === \"string\" ? organization.slug : null;\n\n      if (!nextSlug) {\n        throw new Error(\"Organization was created, but no slug was returned.\");\n      }\n\n      router.push(getOrgDashboardRoute(nextSlug));\n    } finally {\n      setMutationBusy(null);\n    }\n  }\n","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_providers/org-dashboard-provider.tsx#L424-L460","documentation":"createOrganization POSTs { name } to the server (12s timeout) and throws this error when the response is not ok. The organization was not created; the message carries the HTTP status unless the payload includes a server error message via getErrorMessage.","triggerScenarios":"POST create-org returns 401 (expired session), 403 (user lacks permission to create orgs on this deployment), 409 (name/slug conflict with an existing org), 422 (name rejected by server validation, e.g., duplicate or reserved slug), or 5xx.","commonSituations":"Choosing an organization name that already exists (unique slug constraint); users without the create-org entitlement; Den server error during DB write; session expiring mid-form.","solutions":["Read the status: 409/422 → pick a different organization name (server enforces unique slugs).","403 → verify the deployment allows user-created orgs (not single-org mode) and that the user's role permits creation.","401 → re-authenticate, then resubmit the form preserving the entered name.","Inspect the response payload message (getErrorMessage extracts the server's detail) for the precise rejection reason.","For 5xx, check den-api logs; if the org was actually created despite the error (timeout after write), check the org list before retrying to avoid duplicates."],"exampleFix":"// before\nawait createOrganization(name); // 409 on duplicate\n// after\ntry {\n  await createOrganization(name);\n} catch (err) {\n  if (String(err).includes(\"409\") || String(err).includes(\"422\")) {\n    setOrgError(\"That organization name is already taken. Choose another.\");\n    return;\n  }\n  throw err;\n}","handlingStrategy":"try-catch","validationCode":"// check for duplicate names locally before POST\nconst existing = await loadOrgDirectory();\nif (existing.some(o => o.name.toLowerCase() === name.trim().toLowerCase())) {\n  throw new Error(\"An organization with this name already exists.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await createOrganization(name);\n} catch (err) {\n  const m = err.message;\n  if (m.includes(\"409\") || m.includes(\"422\")) showNameTakenError();\n  else if (m.includes(\"401\")) await reauthThenRetry(name);\n  else if (m.includes(\"403\")) showNoPermissionError();\n  else throw err;\n}","preventionTips":["Preserve the entered name across re-auth flows so users never retype.","Debounce/duplicate-guard the create call to prevent double submits creating conflicting slugs.","Before retrying after a timeout, check the org directory — the org may exist despite the error.","Surface the server's payload message (getErrorMessage) for precise feedback.","Monitor 5xx rates on create-org in den-api."],"tags":["http","api","create","den-web"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}