Mintplex-Labs/anything-llm · error · Error

HTTP error! status: ${response.status}

Error message

HTTP error! status: ${response.status}

What it means

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.

Source

Thrown at server/utils/agentFlows/executors/api-call.js:45

    } else if (bodyType === "json") {
      const parsedBody = safeJsonParse(body, null);
      if (parsedBody !== null) {
        requestConfig.body = JSON.stringify(parsedBody);
      }
      requestConfig.headers["Content-Type"] = "application/json";
    } else if (bodyType === "text") {
      requestConfig.body = String(body);
    } else {
      requestConfig.body = body;
    }
  }

  try {
    introspect(`Sending body to ${url}: ${requestConfig?.body || "No body"}`);
    const response = await fetch(url, requestConfig);
    if (!response.ok) {
      introspect(`Request failed with status ${response.status}`);
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    introspect(`API call completed`);
    return await response
      .text()
      .then((text) =>
        safeJsonParse(text, "Failed to parse output from API call block")
      );
  } catch (error) {
    console.error(error);
    throw new Error(`API Call failed: ${error.message}`);
  }
}

module.exports = executeApiCall;

View on GitHub (pinned to 526360e320)

Solutions

  1. Check the status code embedded in the message to identify the failure class (4xx = client/config, 5xx = upstream).
  2. Verify the headers array includes a valid Authorization entry when the endpoint requires auth.
  3. Confirm the URL and HTTP method match the API's documented endpoint.
  4. For 429 responses, back off and retry, or reduce the call frequency.
  5. For 5xx, retry after a delay or check the upstream service status.

Example fix

// before - missing auth header causes 401
{"url":"https://api.example.com/data","method":"GET","headers":[]}
// after - include a valid token
{"url":"https://api.example.com/data","method":"GET","headers":[{"key":"Authorization","value":"Bearer <token>"}]}
Defensive patterns

Strategy: validation

Validate before calling

// validate auth and endpoint shape before executing the API call step
function validateApiCallConfig(config) {
  if (!config.url) throw new Error("API call step missing url");
  if (!config.method) throw new Error("API call step missing method");
  const needsAuth = /auth|token|bearer/i.test(JSON.stringify(config));
  // caller-specific: confirm credentials are present when required
}

Type guard

const isValidHttpStatus = (status) => status >= 200 && status < 300;

Try / catch

// executeApiCall wraps this internally; at the flow layer, catch the re-wrapped 382 error
// and inspect the embedded status code to decide on retry vs surface

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/14217f59d48ebf34. Report an issue: GitHub.