n8n-io/n8n · error · Error
Failed to fetch templates: ${response.status} ${response.sta
Error message
Failed to fetch templates: ${response.status} ${response.statusText} What it means
fetchTemplateList in tools/web/templates.ts issues GET https://api.n8n.io/api/templates/search and throws a plain Error with the HTTP status and statusText when response.ok is false. This is an external API failure: the templates backend returned a non-2xx code (or the fetch itself resolved to an error response).
Source
Thrown at packages/@n8n/ai-workflow-builder.ee/src/tools/web/templates.ts:81
export async function fetchTemplateList(query: {
search?: string;
category?: Category;
rows?: number;
nodes?: string;
}): Promise<TemplateSearchResponse> {
const queryString = buildSearchQueryString(query);
const url = `${N8N_API_BASE_URL}/templates/search${queryString ? `?${queryString}` : ''}`;
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
});
if (!response.ok) {
throw new Error(`Failed to fetch templates: ${response.status} ${response.statusText}`);
}
const data: unknown = await response.json();
if (!isTemplateSearchResponse(data)) {
throw new Error('Invalid response format from templates API');
}
return data;
}
/**
* Fetch a specific workflow template by ID from n8n API
*/
export async function fetchTemplateByID(id: number): Promise<TemplateFetchResponse> {
const url = `${N8N_API_BASE_URL}/workflows/templates/${id}`;
const response = await fetch(url, {
method: 'GET',
headers: {View on GitHub (pinned to 5ac6606e81)
Solutions
- Decode the HTTP status: 429 -> back off and retry; 5xx -> transient, retry with jitter; 4xx -> validate query parameters.
- Retry with exponential backoff (e.g. 3 attempts) for 429/5xx.
- Fall back to a cached/local template list or skip template enrichment.
- Verify network egress to api.n8n.io is permitted (proxy/firewall).
Example fix
// before: single throw on any non-OK
const data = await fetchTemplateList(query);
// after: retry with backoff for transient statuses
async function fetchWithRetry(query, attempts = 3) {
for (let i = 0; i < attempts; i++) {
try { return await fetchTemplateList(query); }
catch (e) {
if (i === attempts - 1) throw e;
await new Promise(r => setTimeout(r, 2 ** i * 500));
}
}
} Defensive patterns
Strategy: retry
Validate before calling
// Validate query shape and retry only on transient statuses.
function isLikelyTransient(status: number): boolean {
return status === 429 || status >= 500;
} Type guard
function isTemplateFetchError(e: unknown): e is Error {
return e instanceof Error && /^Failed to fetch templates:/.test(e.message);
} Try / catch
async function fetchTemplatesWithRetry(query, attempts = 3) {
let lastErr: unknown;
for (let i = 0; i < attempts; i++) {
try {
return await fetchTemplateList(query);
} catch (e) {
lastErr = e;
const m = (e as Error).message;
const status = Number(m.match(/\b(\d{3})\b/)?.[1] ?? 0);
if (!isLikelyTransient(status)) throw e;
await new Promise((r) => setTimeout(r, 2 ** i * 500));
}
}
throw lastErr;
} Prevention
- Wrap fetchTemplateList in exponential backoff for 429/5xx responses.
- Fail fast (no retry) on 4xx other than 429 — those indicate bad query parameters.
- Cache template results to avoid repeated external calls within a session.
- Verify network egress to api.n8n.io in restricted environments.
When it happens
Trigger: api.n8n.io returns 4xx/5xx: 429 rate limit, 5xx outage, 404 from a malformed query string, or a network-layer error surfaced as a non-OK response.
Common situations: n8n template service outage; client network restricted or offline; aggressive polling triggering rate limits; bad search/category/nodes query parameters producing a 4xx; corporate proxy returning a block page.
Related errors
- Invalid response format from templates API
- Failed to fetch template ${id}: ${response.status} ${respons
- Invalid response format from template ${id} API
- Failed to fetch provider catalog: ${response.statusText}
- Supabase upsert failed: ${error.message}
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/17732233dadd8621.
Report an issue: GitHub.