different-ai/openwork · error · Error

Could not save the diagnostic token (${response.status}).

Error message

Could not save the diagnostic token (${response.status}).

What it means

saveBearerToken PUTs { bearerToken } to /v1/diagnostics/egress/token (12s timeout). A non-OK response throws `Could not save the diagnostic token (${response.status})` with any server-provided message preferred by getErrorMessage. On success the draft is cleared, availability is set true, and missing-configuration warnings are cleared; on throw the error surfaces via setError.

Source

Thrown at ee/apps/den-web/app/(den)/dashboard/_components/egress-diagnostics-card.tsx:173

  async function saveBearerToken() {
    if (!canManage) {
      setError("Only workspace owners and super-admins can change the diagnostic token.");
      return;
    }

    const bearerToken = bearerTokenDraft.trim();
    if (bearerToken.length < 24) {
      setError("Enter a diagnostic token with at least 24 characters.");
      return;
    }
    setSavingBearerToken(true);
    setError(null);
    try {
      const { response, payload } = await requestJson("/v1/diagnostics/egress/token", {
        method: "PUT",
        body: JSON.stringify({ bearerToken }),
      }, 12_000);
      if (!response.ok) throw new Error(getErrorMessage(payload, `Could not save the diagnostic token (${response.status}).`));
      setBearerTokenDraft("");
      setAvailable(true);
      setMissingConfiguration([]);
      setEditingBearerToken(false);
    } catch (saveError) {
      setError(saveError instanceof Error ? saveError.message : "Could not save the diagnostic token.");
    } finally {
      setSavingBearerToken(false);
    }
  }

  async function copyRunId() {
    if (!result) return;
    await navigator.clipboard.writeText(result.runId);
    setCopied(true);
  }

  return (

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Check the status code: for 400, trim the token and ensure the field is non-empty before saving.
  2. Re-authenticate if 401/403 and confirm admin rights on the org.
  3. If 404, upgrade the Den server to a version implementing /v1/diagnostics/egress/token.
  4. Inspect Den logs for the PUT and fix any server-side validation or size rejection.
  5. Retry after transient network issues; the 12s timeout can trip on slow links.

Example fix

// before: empty draft submitted
await saveBearerToken(); // server 400 -> "Could not save the diagnostic token (400)."

// after: guard before calling
if (bearerToken.trim().length > 0) {
  await fetch("/v1/diagnostics/egress/token", { method: "PUT", body: JSON.stringify({ bearerToken: bearerToken.trim() }) });
}
Defensive patterns

Strategy: validation

Validate before calling

const token = bearerToken.trim();
if (token.length === 0) {
  setError("Enter a diagnostic token before saving.");
  return; // skip the PUT entirely
}

Type guard

function isNonEmptyToken(v: string): v is string & { __validated: true } {
  return v.trim().length > 0;
}

Try / catch

try {
  await saveBearerToken();
} catch (e) {
  if (isHttpError(e) && e.message.includes("401")) {
    promptReSignIn();
  } else {
    showError(e instanceof Error ? e.message : "Could not save the diagnostic token.");
  }
}

Prevention

When it happens

Trigger: PUT /v1/diagnostics/egress/token returns 400 (empty or malformed bearerToken body), 401/403 (unauthenticated or non-admin), 404 (older Den without the token endpoint), 413 (oversized token), or 5xx backend failure. Network/timeout errors on requestJson land in the catch with the generic fallback message.

Common situations: Submitting an empty token field; pasting a token with surrounding whitespace/newlines the server rejects; session expired mid-edit; self-hosted Den lacking the token route; proxy rejecting large PUT bodies.

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