{"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":56,"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    return await response\n      .text()\n      .then((text) =>\n        safeJsonParse(text, \"Failed to parse output from API call block\")\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":38,"sourceCodeEnd":61,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agentFlows/executors/api-call.js#L38-L61","documentation":"The top-level catch-all in executeApiCall(). Every failure inside the function - the HTTP error (381), a network-level fetch rejection, or a safeJsonParse failure on the response body - is caught here, logged via console.error, and re-thrown as a single wrapped error. Callers receive this message rather than the underlying cause.","triggerScenarios":"Any of: fetch() rejects (DNS failure, connection refused, invalid URL, timeout); response.ok is false (becomes 381 then re-wrapped here); or response.text() cannot be parsed as JSON by safeJsonParse, which returns the fallback string \"Failed to parse output from API call block\" that then becomes this error.","commonSituations":"Offline or unreachable host; misspelled domain; the API returns HTML or plain text instead of JSON; self-signed certificate with no handling; a non-JSON 200 response.","solutions":["Read error.message: if it contains \"HTTP error! status\", treat as an HTTP status problem (see 381); if it contains \"Failed to parse\", the response was not valid JSON.","Confirm the host is reachable and the URL scheme is correct (https vs http).","If the endpoint legitimately returns non-JSON, that is unsupported by this executor - point the flow at a JSON-returning endpoint.","Check server logs (console.error output) for the original error object with its full stack."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: confirm the host resolves and the URL is well-formed\nfunction validateApiUrl(url) {\n  try { new URL(url); } catch { throw new Error(`Invalid API url: ${url}`); }\n}","typeGuard":null,"tryCatchPattern":"try {\n  result = await executeApiCall(config, context);\n} catch (error) {\n  // error.message is \"API Call failed: <cause>\"; inspect the cause substring\n  if (/status: 4\\d\\d/.test(error.message)) handleClientError(error);\n  else if (/Failed to parse/.test(error.message)) handleNonJsonResponse(error);\n  else handleNetworkError(error);\n}","preventionTips":["Point apiCall steps only at endpoints known to return JSON.","Confirm network reachability of the host from the server before relying on the step.","Check server logs (console.error) for the original error object with full detail."],"tags":["api-call","error-handling","network","json-parse"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}