{"record":{"id":"2c8cc211b37647ed","repo":"hcengineering/platform","slug":"workspace-not-found-2c8cc2","errorCode":null,"errorMessage":"Workspace not found","messagePattern":"Workspace not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/server/packages/client/src/account.ts","lineNumber":59,"sourceCode":" *\n * @param token - The authorization token.\n * @param kind - The type of endpoint to retrieve. Can be 'internal', 'external', or 'byregion'. Defaults to 'byregion'.\n * @param timeout - The timeout duration in milliseconds. Defaults to -1 (no timeout).\n * @returns A promise that resolves to the transactor endpoint URL as a string.\n * @throws Will throw an error if the request fails or if the timeout is reached.\n */\nexport async function getTransactorEndpoint (\n  token: string,\n  kind: 'internal' | 'external' | 'byregion' = 'byregion',\n  timeout: number = -1\n): Promise<string> {\n  const accountClient = getAccountClient(token, 30000)\n  const st = Date.now()\n  while (true) {\n    try {\n      const workspaceInfo = await accountClient.selectWorkspace('', kind, externalRegions)\n      if (workspaceInfo === undefined) {\n        throw new Error('Workspace not found')\n      }\n      return workspaceInfo.endpoint\n    } catch (err: any) {\n      if (timeout > 0 && st + timeout < Date.now()) {\n        // Timeout happened\n        throw err\n      }\n      if (connectionErrorCodes.includes(err?.cause?.code)) {\n        await new Promise<void>((resolve) => setTimeout(resolve, 1000))\n      } else {\n        throw err\n      }\n    }\n  }\n}\n\nexport function withRetry<P extends any[], T> (\n  f: (...params: P) => Promise<T>,","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/server/packages/client/src/account.ts#L41-L77","documentation":"getTransactorEndpoint calls accountClient.selectWorkspace('', kind, externalRegions) in a retry loop. If the account service responds with no workspace (undefined result), the function throws 'Workspace not found'. Notably, because this error is thrown inside the try block, it is caught and only rethrown when the timeout has elapsed — otherwise it is treated like a connection error and only retried when err.cause.code is a connection error, otherwise rethrown immediately on the next loop iteration check.","triggerScenarios":"Calling getTransactorEndpoint with a token that has no associated workspace; the account service returns no workspace for the given kind ('internal'/'external'/'byregion') and externalRegions; account service still provisioning (during signup) so selectWorkspace returns undefined.","commonSituations":"Token from a user whose workspace was deleted; region filters (externalRegions) that exclude all available workspaces; calling immediately after workspace creation before the account service has propagated it; wrong auth token or expired session.","solutions":["Verify the token is valid and belongs to a user/workspace that exists","Call with a positive timeout (e.g. 30000) so transient 'no workspace yet' states are retried instead of thrown immediately","Remove/loosen the externalRegions restriction or pass a kind matching an available workspace","Check the account service data to confirm the workspace exists and is active"],"exampleFix":"// before\nconst ep = await getTransactorEndpoint(token) // no timeout; undefined workspace throws fast\n// after\nconst ep = await getTransactorEndpoint(token, 'byregion', 60000) // wait up to 60s for provisioning","handlingStrategy":"retry","validationCode":"// ensure a positive timeout so transient 'no workspace' states are retried rather than thrown\nconst timeoutMs = 30000\nif (!token || typeof token !== 'string' || token.length < 10) throw new Error('Invalid token')","typeGuard":"function isWorkspaceInfo(v: unknown): v is { endpoint: string } {\n  return !!v && typeof v === 'object' && typeof (v as any).endpoint === 'string'\n}","tryCatchPattern":"try {\n  const endpoint = await getTransactorEndpoint(token, 'byregion', 30000)\n} catch (err) {\n  if (err.message === 'Workspace not found') {\n    // token has no workspace, or regions filter excludes everything: check account/provisioning\n  }\n  throw err\n}","preventionTips":["Always pass a positive timeout to getTransactorEndpoint","Validate the token before calling","Confirm workspace provisioning completed before endpoint lookup","Double-check externalRegions/kind arguments match the workspace's actual region/type"],"tags":["account-service","workspace","retry","lookup"],"backgroundTag":"workspace-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}