different-ai/openwork · error

Failed to load organizations.

Error message

Failed to load organizations.

What it means

organization-screen.tsx throws this as the fallback message when `GET /v1/me/orgs` returns a non-ok status and the response payload carries no usable error message. It is the default surfaced to the UI whenever the org list cannot be fetched.

Source

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

    hasMore: orgHasMore,
    showMore: showMoreOrgs,
    showSearch: showOrgSearch,
  } = useOrgListWindow(orgs);

  useEffect(() => {
    if (!sessionHydrated || !runtimeConfigLoaded) return;
    if (!user) {
      router.replace("/");
      return;
    }

    let isMounted = true;

    async function loadOrgs() {
      try {
        const { response, payload } = await requestJson("/v1/me/orgs", { method: "GET" });
        if (!response.ok) {
          throw new Error(getErrorMessage(payload, "Failed to load organizations."));
        }

        if (isMounted) {
          const parsed = parseOrgListPayload(payload);
          const nextOrgs = parsed.orgs.map((org) => ({ ...org, isActive: org.slug === parsed.activeOrgSlug }));
          const targetOrg = nextOrgs.find((org) => org.isActive) ?? nextOrgs[0] ?? null;
          if (isSingleOrgMode && targetOrg) {
            router.replace(getOrgDashboardRoute(targetOrg.slug));
            return;
          }
          setOrgs(nextOrgs);
          setShowCreate(!isSingleOrgMode && nextOrgs.length === 0);
          setBusy(false);
        }
      } catch (err) {
        if (isMounted) {
          setError(err instanceof Error ? err.message : "An error occurred.");
          setBusy(false);

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Check the actual HTTP status of the /v1/me/orgs call in the network tab
  2. Re-authenticate: sign in again to refresh the session token
  3. Verify the Den server is running and reachable at the configured base URL
  4. Add a server-side error body so getErrorMessage returns a meaningful message
Defensive patterns

Strategy: try-catch

Validate before calling

const res = await fetch("/v1/me/orgs");
if (!res.ok) {
  console.warn(`org list preflight failed: ${res.status}`);
}

Type guard

function isOrgListPayload(p: unknown): p is { orgs: { slug: string }[]; activeOrgSlug: string | null } {
  return typeof p === "object" && p !== null && "orgs" in p && Array.isArray((p as { orgs: unknown }).orgs);
}

Try / catch

try {
  const { response, payload } = await requestJson("/v1/me/orgs", { method: "GET" });
  if (!response.ok) throw new Error(getErrorMessage(payload, "Failed to load organizations."));
} catch (err) {
  showRetryableError("Could not load your organizations. Check your sign-in and try again.", { retry: loadOrgs });
}

Prevention

When it happens

Trigger: `requestJson("/v1/me/orgs", { method: "GET" })` resolves with response.ok === false and getErrorMessage cannot extract a message from the payload (e.g. empty body, HTML error page, non-JSON).

Common situations: Auth token expired/missing so the API returns 401 with an empty body; Den server down or proxying to a 502/503 page; network middleware returning HTML error pages instead of JSON.

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/b4cec4d586651b25. Report an issue: GitHub.