{"record":{"id":"baea025a9c445e67","repo":"mastra-ai/mastra","slug":"failed-to-fetch-templates-response-statustext","errorCode":null,"errorMessage":"Failed to fetch templates: ${response.statusText}","messagePattern":"Failed to fetch templates: (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/template-utils.ts","lineNumber":20,"sourceCode":"\nexport interface Template {\n  githubUrl: string;\n  title: string;\n  slug: string;\n  agents: string[];\n  mcp: string[];\n  tools: string[];\n  networks: string[];\n  workflows: string[];\n}\n\nconst TEMPLATES_API_URL = process.env.MASTRA_TEMPLATES_API_URL || 'https://mastra.ai/api/templates.json';\n\nexport async function loadTemplates(): Promise<Template[]> {\n  try {\n    const response = await fetch(TEMPLATES_API_URL);\n    if (!response.ok) {\n      throw new Error(`Failed to fetch templates: ${response.statusText}`);\n    }\n    const templates = (await response.json()) as Template[];\n    return templates;\n  } catch (error) {\n    console.error('Error loading templates:', error);\n    throw new Error('Failed to load templates. Please check your internet connection and try again.');\n  }\n}\n\nfunction pluralize(count: number, singular: string, plural?: string): string {\n  return count === 1 ? singular : plural || `${singular}s`;\n}\n\nexport async function selectTemplate(\n  templates: Template[],\n  options: { signal?: AbortSignal } = {},\n): Promise<Template | null> {\n  const choices = templates.map(template => {","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/utils/template-utils.ts#L2-L38","documentation":"loadTemplates fetches the Mastra templates JSON (https://mastra.ai/api/templates.json, overridable via MASTRA_TEMPLATES_API_URL) and throws this error when the HTTP response is not ok (any 4xx/5xx status). It is immediately caught and rethrown as the generic 'Failed to load templates...' error [1009].","triggerScenarios":"Running the create-mastra templates command (`mastra templates`/create flow) when the templates API returns a non-OK response: 404 (wrong URL), 403 (rate limit/CDN block), 5xx (server outage).","commonSituations":"MASTRA_TEMPLATES_API_URL pointing at a wrong/removed endpoint; mastra.ai outage or CDN rate limiting; corporate proxy returning 403; offline with a captive portal returning HTML error pages.","solutions":["Check https://mastra.ai/api/templates.json is reachable (curl -I) and retry after the outage passes.","If MASTRA_TEMPLATES_API_URL is set, verify it points to a valid templates.json endpoint or unset it to use the default.","Check for proxy/firewall/VPN interference and rate limiting; use the correct network or wait out the rate limit."],"exampleFix":"// before\nexport MASTRA_TEMPLATES_API_URL=https://internal.example.com/old-templates.json\n// 404 -> Failed to fetch templates: Not Found\n\n// after\nunset MASTRA_TEMPLATES_API_URL   # fall back to https://mastra.ai/api/templates.json","handlingStrategy":"retry","validationCode":"const res = await fetch(TEMPLATES_API_URL, { method: 'HEAD' });\nif (!res.ok) throw new Error(`Templates API unavailable: ${res.status}`);","typeGuard":null,"tryCatchPattern":"async function loadTemplatesWithRetry(retries = 3) {\n  for (let i = 0; i < retries; i++) {\n    try { return await loadTemplates(); }\n    catch (err) {\n      if (i === retries - 1) throw err;\n      await new Promise(r => setTimeout(r, 2 ** i * 500));\n    }\n  }\n}","preventionTips":["Monitor mastra.ai status before running the templates command in CI.","Do not override MASTRA_TEMPLATES_API_URL unless the replacement endpoint is verified.","Use exponential backoff retries for transient 429/5xx responses."],"tags":["network","http","api","cli"],"backgroundTag":"http-request-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}