different-ai/openwork · error

Could not prepare an OpenWork link

Error message

Could not prepare an OpenWork link (${response.status}).

What it means

workspace-claim-screen.tsx throws this when the desktop-handoff request (POST with `desktopScheme: "openwork"`, 12s timeout) returns a non-ok HTTP status, using the status code in the message. It is the fallback when the payload has no usable error detail.

Solutions

  1. Read the interpolated status code and inspect the matching request in the network tab
  2. Refresh the claim page so a fresh claim/session token is used
  3. Retry after confirming the Den server is healthy (server 5xx is often transient)
  4. Check auth: ensure the user completed sign-in before requesting the handoff link
Defensive patterns

Strategy: retry

Validate before calling

// Preflight: only request the handoff when a session exists
const me = await fetch("/v1/me");
if (!me.ok) {
  redirectToSignIn();
  return;
}

Try / catch

try {
  const link = await createDesktopHandoff();
} catch (err) {
  if (err.message.includes("(40") ) showAuthError("Your claim session expired. Refresh the page and try again.");
  else showRetryableError("Could not prepare an OpenWork link. Please retry in a moment.");
}

Prevention

When it happens

Trigger: The handoff endpoint responds 4xx/5xx (e.g. 401 unauthenticated claim, 500 server error, 504 after the 12-second timeout kills the request upstream) and getErrorMessage cannot extract a message from the body.

Common situations: Claim token expired so the server returns 403/404; Den server under load returning 500; reverse proxy timing out before the 12s client timeout; user not yet signed in when clicking 'Open desktop'.

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

Appendix: source

Thrown at ee/apps/den-web/app/(den)/_components/workspace-claim-screen.tsx:211

    if (window.sessionStorage.getItem(AUTO_ACCEPT_WORKSPACE_CLAIM_STORAGE_KEY) !== token) return;

    autoClaimAttempted.current = true;
    window.sessionStorage.removeItem(AUTO_ACCEPT_WORKSPACE_CLAIM_STORAGE_KEY);
    void handleClaim();
  }, [claimBusy, claimedOrg, sessionHydrated, token, user]);

  async function createDesktopHandoff(): Promise<string> {
    const { response, payload } = await requestJson(
      "/v1/auth/desktop-handoff",
      {
        method: "POST",
        body: JSON.stringify({ desktopScheme: "openwork" }),
      },
      12000,
    );

    if (!response.ok) {
      throw new Error(getErrorMessage(payload, `Could not prepare an OpenWork link (${response.status}).`));
    }

    const openworkUrl = getOpenworkUrl(payload);
    if (!openworkUrl) {
      throw new Error("No OpenWork link was returned.");
    }

    return openworkUrl;
  }

  async function handleOpenDesktop() {
    setHandoffBusy(true);
    setHandoffError(null);
    setHandoffAttempted(true);

    try {
      window.location.assign(await createDesktopHandoff());
    } catch (error) {

View on GitHub (pinned to 2b7df46e8a)