{"record":{"id":"8cf9579ee3211c8b","repo":"different-ai/openwork","slug":"failed-to-grant-access-response-status","errorCode":null,"errorMessage":"Failed to grant access (${response.status}).","messagePattern":"Failed to grant access \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/marketplace-data.tsx","lineNumber":299,"sourceCode":"      body:\n        | { orgWide: true; role?: MarketplaceAccessRole }\n        | { teamId: string; role?: MarketplaceAccessRole }\n        | { orgMembershipId: string; role?: MarketplaceAccessRole };\n    }) => {\n      await runReauthableAction(\"grant-marketplace-access\", async () => {\n      const body = {\n        role: input.body.role ?? \"viewer\",\n        ...(\"orgWide\" in input.body ? { orgWide: true } : {}),\n        ...(\"teamId\" in input.body ? { teamId: input.body.teamId } : {}),\n        ...(\"orgMembershipId\" in input.body ? { orgMembershipId: input.body.orgMembershipId } : {}),\n      };\n      const { response, payload } = await requestJson(\n        `/v1/marketplaces/${encodeURIComponent(input.marketplaceId)}/access`,\n        { method: \"POST\", body: JSON.stringify(body) },\n        15000,\n      );\n      if (!response.ok) {\n        throw getRequestError(payload, response, `Failed to grant access (${response.status}).`);\n      }\n      });\n      return input.marketplaceId;\n    },\n    onSuccess: (marketplaceId) => {\n      queryClient.invalidateQueries({ queryKey: marketplaceQueryKeys.access(marketplaceId) });\n      queryClient.invalidateQueries({ queryKey: marketplaceQueryKeys.resolved(marketplaceId) });\n    },\n  });\n}\n\nexport function useRevokeMarketplaceAccess() {\n  const queryClient = useQueryClient();\n  const { runReauthableAction } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (input: { marketplaceId: string; grantId: string }) => {\n      await runReauthableAction(\"revoke-marketplace-access\", async () => {","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/marketplace-data.tsx#L281-L317","documentation":"Thrown by useGrantMarketplaceAccess in marketplace-data.tsx when POST /v1/marketplaces/{marketplaceId}/access (15s timeout) returns non-ok. getRequestError (den-flow.ts:527) turns a 403 {error:'reauth'} payload into ReauthRequiredError and otherwise yields the server `error` message or the fallback \"Failed to grant access (<status>).\".","triggerScenarios":"Granting a member/team access to a private marketplace returns non-ok: 401/403 (caller is not an org owner/admin or session expired), 404 (marketplace id or grantee id does not exist), 409 (access already granted), 422 (invalid grantee or body), 429 (plan/seat limits on marketplace access), 5xx, or the 15s timeout.","commonSituations":"Granting to a user removed from the org; duplicating a grant from double-click; non-admin opening the marketplace share dialog; grant body missing required fields after a marketplace schema change on the server.","solutions":["On 409, treat as success: the grant already exists — invalidate marketplaceQueryKeys.access(marketplaceId) and update the UI.","On 404, refresh the marketplace and member lists; the marketplace or grantee is gone.","For 403, confirm admin/owner role and complete reauth when isReauthRequiredError(error) is true.","On 429, check the org plan/seat limits before retrying the grant."],"exampleFix":"// before\nif (!response.ok) {\n  throw getRequestError(payload, response, `Failed to grant access (${response.status}).`);\n}\n// after\nif (!response.ok) {\n  if (response.status === 409) return input.marketplaceId; // already granted\n  throw getRequestError(payload, response, `Failed to grant access (${response.status}).`);\n}","handlingStrategy":"try-catch","validationCode":"// before granting\nif (!marketplaceId) throw new Error(\"marketplaceId is required.\");\nif (!granteeIds.length) throw new Error(\"Select at least one member or team.\");\nconst missing = granteeIds.filter((id) => !activeMembers.some((m) => m.id === id));\nif (missing.length) throw new Error(`Unknown grantee(s): ${missing.join(\", \")}`);","typeGuard":"function isReauthError(e: unknown): e is ReauthRequiredError {\n  return e instanceof ReauthRequiredError;\n}","tryCatchPattern":"try {\n  await grantMutation.mutateAsync({ marketplaceId, ...body });\n} catch (error) {\n  if (isReauthError(error)) { startReauth(); return; }\n  if (/\\(409\\)/.test(error.message)) { await queryClient.invalidateQueries(marketplaceQueryKeys.access(marketplaceId)); return; }\n  showToast(error.message);\n}","preventionTips":["Filter out already-granted members in the share dialog to prevent 409s.","Refresh the member list before granting to avoid grants to removed users (404).","Gate the grant UI on owner/admin role.","Invalidate marketplaceQueryKeys.access after any grant attempt, success or conflict."],"tags":["http","marketplace","den-api","access-control"],"backgroundTag":"http-non-ok-response","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}