{"record":{"id":"fb2564a3c0d20e29","repo":"different-ai/openwork","slug":"failed-to-create-collection-response-status","errorCode":null,"errorMessage":"Failed to create collection (${response.status}).","messagePattern":"Failed to create collection \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/marketplace-data.tsx","lineNumber":447,"sourceCode":"  const { runReauthableAction } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (input: { name: string; description?: string }): Promise<DenMarketplace> => {\n      let created: DenMarketplace | null = null;\n      await runReauthableAction(\"create-marketplace\", async () => {\n        const { response, payload } = await requestJson(\n          \"/v1/marketplaces\",\n          {\n            method: \"POST\",\n            body: JSON.stringify({\n              name: input.name,\n              ...(input.description ? { description: input.description } : {}),\n            }),\n          },\n          15000,\n        );\n        if (!response.ok) {\n          throw getRequestError(payload, response, `Failed to create collection (${response.status}).`);\n        }\n        created = isRecord(payload) && isRecord(payload.item) ? parseMarketplace(payload.item) : null;\n      });\n      if (!created) {\n        throw new Error(\"Collection create response was incomplete.\");\n      }\n      return created;\n    },\n    onSuccess: () => {\n      queryClient.invalidateQueries({ queryKey: marketplaceQueryKeys.all });\n    },\n  });\n}\n\nexport function useUpdateMarketplace() {\n  const queryClient = useQueryClient();\n  const { runReauthableAction } = useOrgDashboard();\n","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/marketplace-data.tsx#L429-L465","documentation":"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.","triggerScenarios":"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.","commonSituations":"User session expired; org role downgraded so creating collections is forbidden; duplicate collection name; oversized description; Den server errors during deployments.","solutions":["Check the status in the message: for 401/403, re-authenticate or obtain marketplace-create permission for the org.","For 400/409/422, fix the submitted name/description (uniqueness, length) and resubmit.","For 5xx, retry with backoff and check Den server health.","Surface isReauthRequiredError to trigger the re-auth flow rather than a generic toast."],"exampleFix":"// before\nawait createMutation.mutateAsync({ name });\n// after\ntry {\n  await createMutation.mutateAsync({ name });\n} catch (err) {\n  if (isReauthRequiredError(err)) { startReauth(); }\n  else setCreateError(err.message);\n}","handlingStrategy":"try-catch","validationCode":"// before createMutation.mutateAsync\nconst name = input.name?.trim();\nif (!name) throw new Error(\"Collection name is required\");\nif (name.length > 120) throw new Error(\"Collection name is too long\");\nif (existingNames.has(name)) throw new Error(\"A collection with this name already exists\");","typeGuard":"function isReauthError(err: unknown): err is ReauthRequiredError {\n  return err instanceof ReauthRequiredError;\n}","tryCatchPattern":"try {\n  await createMutation.mutateAsync(input);\n} catch (err) {\n  if (isReauthRequiredError(err)) startReauth();\n  else setFormError(err.message);\n}","preventionTips":["Check for duplicate names client-side before submitting","Enforce name/description length limits in the form","Re-authenticate when idle sessions are detected","Show the thrown message (contains the HTTP status) in UI error surfaces"],"tags":["http","den-api","marketplace"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}