{"record":{"id":"14217f59d48ebf34","repo":"Mintplex-Labs/anything-llm","slug":"http-error-status-response-status","errorCode":null,"errorMessage":"HTTP error! status: ${response.status}","messagePattern":"HTTP error! status: (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agentFlows/executors/api-call.js","lineNumber":45,"sourceCode":"    } else if (bodyType === \"json\") {\n      const parsedBody = safeJsonParse(body, null);\n      if (parsedBody !== null) {\n        requestConfig.body = JSON.stringify(parsedBody);\n      }\n      requestConfig.headers[\"Content-Type\"] = \"application/json\";\n    } else if (bodyType === \"text\") {\n      requestConfig.body = String(body);\n    } else {\n      requestConfig.body = body;\n    }\n  }\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":27,"sourceCodeEnd":61,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agentFlows/executors/api-call.js#L27-L61","documentation":"Thrown inside executeApiCall() when fetch() resolves but response.ok is false (any non-2xx status). It is thrown inside the function's try block, so it is immediately caught by the outer catch at line 54 and re-wrapped as \"API Call failed: ...\" (error 382). This means the raw HTTP status message never reaches the caller verbatim; it appears nested inside the API Call failed message.","triggerScenarios":"The target API responds with an HTTP status outside the 200-299 range: 401/403 for auth failures, 404 for a wrong endpoint, 429 for rate limiting, or 5xx for upstream server errors. The fetch itself succeeded at the network layer; only the application-level response failed.","commonSituations":"Missing or expired Authorization token in the headers array; typo in the URL; the endpoint requires a different HTTP method than configured; the provider rate-limits the request; the upstream service is down.","solutions":["Check the status code embedded in the message to identify the failure class (4xx = client/config, 5xx = upstream).","Verify the headers array includes a valid Authorization entry when the endpoint requires auth.","Confirm the URL and HTTP method match the API's documented endpoint.","For 429 responses, back off and retry, or reduce the call frequency.","For 5xx, retry after a delay or check the upstream service status."],"exampleFix":"// before - missing auth header causes 401\n{\"url\":\"https://api.example.com/data\",\"method\":\"GET\",\"headers\":[]}\n// after - include a valid token\n{\"url\":\"https://api.example.com/data\",\"method\":\"GET\",\"headers\":[{\"key\":\"Authorization\",\"value\":\"Bearer <token>\"}]}","handlingStrategy":"validation","validationCode":"// validate auth and endpoint shape before executing the API call step\nfunction validateApiCallConfig(config) {\n  if (!config.url) throw new Error(\"API call step missing url\");\n  if (!config.method) throw new Error(\"API call step missing method\");\n  const needsAuth = /auth|token|bearer/i.test(JSON.stringify(config));\n  // caller-specific: confirm credentials are present when required\n}","typeGuard":"const isValidHttpStatus = (status) => status >= 200 && status < 300;","tryCatchPattern":"// executeApiCall wraps this internally; at the flow layer, catch the re-wrapped 382 error\n// and inspect the embedded status code to decide on retry vs surface","preventionTips":["Verify required auth headers are present in the step config before running the flow.","Test the endpoint independently (curl) to confirm it returns 2xx for your credentials.","Use variables for tokens so they can be rotated without editing the flow JSON."],"tags":["api-call","http","response-status","agent-flows"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}