{"record":{"id":"518982b466fd9342","repo":"different-ai/openwork","slug":"could-not-save-the-diagnostic-token-response-st","errorCode":null,"errorMessage":"Could not save the diagnostic token (${response.status}).","messagePattern":"Could not save the diagnostic token \\((.+?)\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/egress-diagnostics-card.tsx","lineNumber":173,"sourceCode":"  async function saveBearerToken() {\n    if (!canManage) {\n      setError(\"Only workspace owners and super-admins can change the diagnostic token.\");\n      return;\n    }\n\n    const bearerToken = bearerTokenDraft.trim();\n    if (bearerToken.length < 24) {\n      setError(\"Enter a diagnostic token with at least 24 characters.\");\n      return;\n    }\n    setSavingBearerToken(true);\n    setError(null);\n    try {\n      const { response, payload } = await requestJson(\"/v1/diagnostics/egress/token\", {\n        method: \"PUT\",\n        body: JSON.stringify({ bearerToken }),\n      }, 12_000);\n      if (!response.ok) throw new Error(getErrorMessage(payload, `Could not save the diagnostic token (${response.status}).`));\n      setBearerTokenDraft(\"\");\n      setAvailable(true);\n      setMissingConfiguration([]);\n      setEditingBearerToken(false);\n    } catch (saveError) {\n      setError(saveError instanceof Error ? saveError.message : \"Could not save the diagnostic token.\");\n    } finally {\n      setSavingBearerToken(false);\n    }\n  }\n\n  async function copyRunId() {\n    if (!result) return;\n    await navigator.clipboard.writeText(result.runId);\n    setCopied(true);\n  }\n\n  return (","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/egress-diagnostics-card.tsx#L155-L191","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the status code: for 400, trim the token and ensure the field is non-empty before saving.","Re-authenticate if 401/403 and confirm admin rights on the org.","If 404, upgrade the Den server to a version implementing /v1/diagnostics/egress/token.","Inspect Den logs for the PUT and fix any server-side validation or size rejection.","Retry after transient network issues; the 12s timeout can trip on slow links."],"exampleFix":"// before: empty draft submitted\nawait saveBearerToken(); // server 400 -> \"Could not save the diagnostic token (400).\"\n\n// after: guard before calling\nif (bearerToken.trim().length > 0) {\n  await fetch(\"/v1/diagnostics/egress/token\", { method: \"PUT\", body: JSON.stringify({ bearerToken: bearerToken.trim() }) });\n}","handlingStrategy":"validation","validationCode":"const token = bearerToken.trim();\nif (token.length === 0) {\n  setError(\"Enter a diagnostic token before saving.\");\n  return; // skip the PUT entirely\n}","typeGuard":"function isNonEmptyToken(v: string): v is string & { __validated: true } {\n  return v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await saveBearerToken();\n} catch (e) {\n  if (isHttpError(e) && e.message.includes(\"401\")) {\n    promptReSignIn();\n  } else {\n    showError(e instanceof Error ? e.message : \"Could not save the diagnostic token.\");\n  }\n}","preventionTips":["Trim and non-empty check the token in the form before submitting.","Confirm the Den server version includes /v1/diagnostics/egress/token (404 guard).","Refresh the session if the user idled on the token editor before saving.","Avoid proxy body-size limits by keeping the token field to the expected token length."],"tags":["network","http","token","diagnostics"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}