{"record":{"id":"544813667bbe433f","repo":"mastra-ai/mastra","slug":"failed-to-create-project-await-extracterror-re","errorCode":null,"errorMessage":"Failed to create project — ${await extractError(res)}","messagePattern":"Failed to create project — (.+?)","errorType":"http","errorClass":"PlatformApiError","httpStatus":null,"severity":"error","filePath":"mastracode/mastra-factory/src/platform.ts","lineNumber":84,"sourceCode":"/** POST /v1/server/projects — create a server project (Railway-provisioned). */\nexport async function createServerProject({\n  token,\n  orgId,\n  name,\n  region,\n}: {\n  token: string;\n  orgId: string;\n  name: string;\n  region: ProjectRegion;\n}): Promise<PlatformProject> {\n  const res = await platformFetch(`${MASTRA_PLATFORM_API_URL}/v1/server/projects`, {\n    method: 'POST',\n    headers: { ...authHeaders(token, orgId), 'Content-Type': 'application/json' },\n    body: JSON.stringify({ name, region, factoryEnabled: true }),\n  });\n  if (!res.ok) {\n    throw new PlatformApiError(res.status, `Failed to create project — ${await extractError(res)}`);\n  }\n  const body = (await res.json()) as CreateProjectResponse;\n  return body.project;\n}\n\n/**\n * POST /v1/auth/tokens — mint an `sk_` WorkOS org API key.\n * Returns the plaintext secret; the platform never returns it again.\n */\nexport async function mintOrgApiKey({\n  token,\n  orgId,\n  keyName,\n}: {\n  token: string;\n  orgId: string;\n  keyName: string;\n}): Promise<string> {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/mastra-factory/src/platform.ts#L66-L102","documentation":"createServerProject POSTs to /v1/server/projects with `{ name, region, factoryEnabled: true }`. Any non-ok response is converted into a PlatformApiError carrying the upstream HTTP status and the server-provided error body (via extractError) prefixed with 'Failed to create project —'.","triggerScenarios":"POST /v1/server/projects returns 4xx/5xx: e.g. 401/403 for bad/expired token or missing role, 409 for a duplicate project name, 400 for an invalid region or name, 500 for a platform-side outage.","commonSituations":"Expired auth token after a long session; project name already used in the org; unsupported or typo'd region id; org admin permissions missing; platform maintenance window returning 502/503.","solutions":["Read the status and message after the em-dash in the error; fix the specific cause (e.g. choose another name on 409, re-login on 401).","Verify the region id against the platform's supported region list.","Re-authenticate (`mastra auth login`) if the token is stale, and confirm your org role allows project creation.","Retry after a short wait if the status is 5xx (platform-side issue)."],"exampleFix":"// before\nawait createServerProject({ token, orgId, name: 'my-factory', region: 'us-east-1' });\n// after\nconst REGIONS = ['us-east-1', 'us-west-2']; // confirmed against platform docs\nif (!REGIONS.includes(region)) throw new Error(`Unsupported region: ${region}`);\nawait createServerProject({ token, orgId, name: 'my-factory', region });","handlingStrategy":"try-catch","validationCode":"if (!/^[a-zA-Z0-9][a-zA-Z0-9-_]*$/.test(projectName)) throw new Error('Invalid project name');\nif (!supportedRegions.includes(region)) throw new Error(`Unsupported region: ${region}`);\nconst existing = await listServerProjects({ token, orgId });\nif (existing.some(p => p.name === projectName)) throw new Error(`Project name '${projectName}' already in use`);","typeGuard":"function isPlatformApiError(e) { return e instanceof PlatformApiError; }","tryCatchPattern":"try {\n  const project = await createServerProject({ token, orgId, name, region });\n} catch (err) {\n  if (err instanceof PlatformApiError && err.status === 409) {\n    name = `${name}-${Date.now()}`; // retry with unique name\n  } else if (err instanceof PlatformApiError && err.status === 401) {\n    await refreshAuth();\n  } else throw err;\n}","preventionTips":["Refresh tokens before long provisioning runs.","Pre-check project name uniqueness within the org.","Validate region ids against the platform's supported list.","Handle 5xx with exponential backoff retries."],"tags":["http-error","platform-api","project-creation","network"],"backgroundTag":"http-api-error","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}