{"record":{"id":"4a09bbadc26c37d8","repo":"Mintplex-Labs/anything-llm","slug":"api-call-failed-error-message","errorCode":null,"errorMessage":"API Call failed: ${error.message}","messagePattern":"API Call failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agentFlows/executors/api-call.js","lineNumber":60,"sourceCode":"  }\n\n  try {\n    introspect(`Sending body to ${url}: ${requestConfig?.body || \"No body\"}`);\n    const response = await fetch(url, requestConfig);\n    if (!response.ok) {\n      introspect(`Request failed with status ${response.status}`);\n      throw new Error(`HTTP error! status: ${response.status}`);\n    }\n\n    introspect(`API call completed`);\n    const responseText = await response.text();\n    try {\n      // JSON bodies parse into values; anything else (plain text, HTML,\n      // empty bodies) is passed through verbatim. We intentionally avoid\n      // safeJsonParse here so non-JSON bodies are never \"repaired\" into\n      // invented JSON or reduced to an embedded JSON substring.\n      return JSON.parse(responseText);\n    } catch {\n      return responseText;\n    }\n  } catch (error) {\n    console.error(error);\n    throw new Error(`API Call failed: ${error.message}`);\n  }\n}\n\nmodule.exports = executeApiCall;\n","sourceCodeStart":42,"sourceCodeEnd":70,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/agentFlows/executors/api-call.js#L42-L70","documentation":"The catch-all wrapper at the bottom of executeApiCall: every failure in the API Call block — network-level fetch errors (DNS, ECONNREFUSED, TLS), the 'HTTP error! status: N' throw above, and safeJsonParse failures ('Failed to parse output from API call block') — is logged with console.error and rethrown as 'API Call failed: <original message>'. The root cause survives only inside the message suffix after the colon.","triggerScenarios":"Any API Call block execution where fetch throws (invalid URL scheme, unreachable host, certificate error), the response is non-2xx, or the response text is not valid JSON when a JSON result was expected. The wrapped message nests: 'API Call failed: HTTP error! status: 404' or 'API Call failed: fetch failed'.","commonSituations":"Typo'd URL or missing https://; server cannot resolve/reach the target (Docker network isolation); self-signed certificate on an internal endpoint; remote returns HTML error page that JSON-parsing rejects; proxy/firewall blocking egress from the container.","solutions":["Read the text after 'API Call failed:' — it preserves the underlying cause ('fetch failed', 'HTTP error! status: N', 'Failed to parse output...').","For 'fetch failed', test connectivity from the same host/container: curl -v <url>.","For parse failures, check whether the endpoint returns JSON for the given method/headers, or switch the block to consume the text response.","Verify the URL string produced after variable substitution (see the 'Sending body/URL' introspect lines)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"function apiCallBlockConfigOk(config) {\n  try {\n    const u = new URL(config.url);\n    return /^https?:$/.test(u.protocol);\n  } catch {\n    return false;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runFlow();\n} catch (e) {\n  if (e.message.startsWith(\"API Call failed:\")) {\n    const cause = e.message.slice(\"API Call failed:\".length).trim();\n    // cause is the real reason: 'fetch failed' | 'HTTP error! status: N' | parse failure\n    if (cause.includes(\"fetch failed\")) return reportNetwork(cause);\n    if (/HTTP error! status: 4\\d\\d/.test(cause)) return reportConfig(cause);\n    return reportUpstream(cause);\n  }\n  throw e;\n}","preventionTips":["Always unwrap the suffix after 'API Call failed:' before debugging — the root cause lives there.","Confirm the target returns JSON when the block expects a parsed result, or handle text responses.","Verify container egress (DNS, proxy, firewall) for every new external endpoint used by a flow."],"tags":["http","fetch","api-call","agent-flows","error-wrapping"],"backgroundTag":"http-request-failed","analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}