{"record":{"id":"c3d82944fb1736ce","repo":"different-ai/openwork","slug":"failed-to-load-team-access-response-status","errorCode":null,"errorMessage":"Failed to load team access (${response.status}).","messagePattern":"Failed to load team access \\((.+?)\\)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/team-access-data.tsx","lineNumber":122,"sourceCode":"    marketplace,\n    role,\n    grantedBy,\n    grantedAt,\n    grantId,\n  };\n}\n\nexport function useTeamPluginAccess(teamId: string) {\n  return useQuery({\n    queryKey: teamAccessQueryKeys.detail(teamId),\n    queryFn: async (): Promise<TeamPluginAccessItem[]> => {\n      const { response, payload } = await requestJson(\n        `/v1/teams/${encodeURIComponent(teamId)}/plugin-access`,\n        { method: \"GET\" },\n        15000,\n      );\n      if (!response.ok) {\n        throw new Error(getErrorMessage(payload, `Failed to load team access (${response.status}).`));\n      }\n\n      const items = isRecord(payload) && Array.isArray(payload.items) ? payload.items : [];\n      return items\n        .map(parseTeamPluginAccessItem)\n        .filter((item): item is TeamPluginAccessItem => item !== null);\n    },\n  });\n}\n\nexport function useRevokeTeamPluginAccess() {\n  const queryClient = useQueryClient();\n  const { runReauthableAction } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (input: { teamId: string; pluginId: string; grantId: string }) => {\n      await runReauthableAction(\"revoke-team-plugin-access\", async () => {\n        const { response, payload } = await requestJson(","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/team-access-data.tsx#L104-L140","documentation":"useTeamPluginAccess GETs /v1/teams/{teamId}/plugin-access and, when the response is not ok, throws an Error built from getErrorMessage(payload, fallback) where fallback is 'Failed to load team access (${status}).' It surfaces the server's error message when present, otherwise the HTTP status.","triggerScenarios":"GET team plugin-access returns 401 (unauthenticated), 403 (not a team member/admin), 404 (bad teamId), or 5xx from the Den API.","commonSituations":"Session expired mid-dashboard-use; user switched orgs and the teamId belongs to another org; teamId malformed in route; Den API outage or timeout returning 5xx.","solutions":["Check response.status: 401 → re-authenticate / refresh the session; 403 → request team admin access; 404 → verify teamId.","Confirm the teamId in the route/query actually exists in the current org.","Retry after auth fix — react-query will refetch; clear cached errors.","If 5xx persists, check Den API health/logs; the failure is server-side."],"exampleFix":"// before\nthrow new Error(getErrorMessage(payload, `Failed to load team access (${response.status}).`));\n// after\nif (response.status === 401) { await reauthenticate(); }\nthrow new Error(getErrorMessage(payload, `Failed to load team access (${response.status}).`));","handlingStrategy":"retry","validationCode":"function isValidTeamId(teamId: string): boolean {\n  return teamId.length > 0 && /^[%\\w-]+$/.test(encodeURIComponent(teamId));\n}","typeGuard":"function isTeamAccessPayload(v: unknown): v is { items: unknown[] } {\n  return isRecord(v) && Array.isArray(v.items);\n}","tryCatchPattern":"try {\n  const access = await accessQuery.refetch();\n} catch (e) {\n  const msg = e instanceof Error ? e.message : \"\";\n  const status = /\\((\\d{3})\\)/.exec(msg)?.[1];\n  if (status === \"401\") await reauthenticate();\n  else if (status === \"403\") showNoAccessState();\n  else if (status?.startsWith(\"5\")) queueRetry();\n}","preventionTips":["Check auth state before mounting team-scoped queries","Validate teamId against the current org before fetching","Add retry with backoff for 5xx in the query's retry fn"],"tags":["http","api","network"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}