different-ai/openwork · error

Failed to load library (${response.status}).

Error message

Failed to load library (${response.status}).

What it means

useLibrary's query function calls GET /v1/me/library via requestJson; when the HTTP response is not ok it throws an Error whose message prefers a server-provided message (getErrorMessage) and otherwise embeds the HTTP status. This surfaces transport-level failures (auth, server error, not found) to React Query's error state.

Source

Thrown at ee/apps/den-web/app/(den)/dashboard/_components/library-data.tsx:284

    .filter((item): item is LibraryItem => item !== null);
  const supportedItemCount = payload.items.filter((item) => !isRecord(item) || item.type !== "app").length;
  if (items.length !== supportedItemCount) {
    throw new Error("Library response was incomplete.");
  }
  return items;
}

export function useLibrary() {
  return useQuery({
    queryKey: libraryQueryKeys.items,
    queryFn: async (): Promise<LibraryItem[]> => {
      const { response, payload } = await requestJson(
        "/v1/me/library",
        { method: "GET" },
        15000,
      );
      if (!response.ok) {
        throw new Error(getErrorMessage(payload, `Failed to load library (${response.status}).`));
      }
      return parseLibraryPayload(payload);
    },
  });
}

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Check response.status in the error and the server message from getErrorMessage to identify 401/403/404/5xx.
  2. For 401, re-authenticate the user (refresh session or redirect to sign-in).
  3. For 404, confirm the frontend talks to a server version that implements /v1/me/library.
  4. For 5xx, check den-api server logs and retry once the backend recovers.
  5. Confirm the request includes the correct org/auth headers expected by the endpoint.

Example fix

// before
throw new Error(getErrorMessage(payload, `Failed to load library (${response.status}).`));
// after (distinguish auth failures for redirect handling)
if (response.status === 401) throw new LibraryAuthError(getErrorMessage(payload, "Sign in required."));
throw new Error(getErrorMessage(payload, `Failed to load library (${response.status}).`));
Defensive patterns

Strategy: try-catch

Try / catch

const { isLoading, data, error } = useLibrary();
if (error) {
  const m = error instanceof Error ? error.message : String(error);
  if (/\(401\)/.test(m)) redirectToSignIn();
  else showRetryBanner(`Library unavailable: ${m}`);
}

Prevention

When it happens

Trigger: GET /v1/me/library responds with 401 (expired/missing session), 403 (no org access), 404 (route missing/old server), 429, or 5xx (backend failure); network-layer completion with non-2xx status.

Common situations: Session token expired while the dashboard is open; user lacks the organization that owns the library; deployed web frontend points at a server without this route; backend outage or rate limiting.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/ef84d28999ce683d. Report an issue: GitHub.