Mintplex-Labs/anything-llm · warning

Unexpected response format for ${endpoint}:

Error message

Unexpected response format for ${endpoint}:

What it means

The paginated GitLab endpoint answered 200 but response.json() was not an array — GitLab list endpoints return JSON arrays, so an object body means the request did not hit a real list endpoint (or the server returned a JSON error object with status 200). The loader warns and returns an empty list for that resource.

Source

Thrown at collector/utils/extensions/RepoLoader/GitlabRepo/RepoLoader/index.js:423

      }

      if (response.status === 401) {
        console.warn(
          `[Gitlab Loader]: Unauthorized request for ${endpoint}. Skipping.`
        );
        return null;
      }

      if (!response.ok) {
        console.warn(
          `[Gitlab Loader]: Unexpected status ${response.status} for ${endpoint}. Skipping.`
        );
        return null;
      }

      const data = await response.json();
      if (!Array.isArray(data)) {
        console.warn(`Unexpected response format for ${endpoint}:`, data);
        return [];
      }

      // GitLab omits x-total-pages for large repos, so use x-next-page
      // as the sole pagination signal — it's empty on the last page.
      const nextPage = response.headers.get("x-next-page");
      const totalPages = response.headers.get("x-total-pages");
      console.log(
        `Gitlab RepoLoader: fetched ${endpoint} page ${requestData.page}${
          totalPages ? `/${totalPages}` : ""
        } with ${data.length} records.`
      );

      requestData.page = nextPage?.trim() ? Number(nextPage) : -1;

      return data;
    } catch (e) {
      console.error(`RepoLoader.fetchNextPage`, e);

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Set apiBase to the bare GitLab root (e.g. https://gitlab.example.com) so /api/v4/... resolves correctly.
  2. curl the exact failing URL with the token and inspect whether the body is an array.
  3. Bypass or configure SSO/proxy gates so API paths are served by GitLab directly.
  4. Confirm the GitLab version supports the endpoint being paginated.
Defensive patterns

Strategy: type-guard

Validate before calling

// Verify the endpoint returns an array before delegating to the loader:
const resp = await fetch(`${apiBase}/api/v4/projects/${id}/repository/tree?per_page=1`, {
  headers: { 'PRIVATE-TOKEN': accessToken },
});
const body = await resp.json();
if (!Array.isArray(body)) throw new Error('apiBase does not resolve to the GitLab API — check base URL/proxy');

Type guard

function isGitlabListPayload(data) {
  return Array.isArray(data);
}

Prevention

When it happens

Trigger: apiBase misconfigured so the built /api/v4/... URL resolves to a non-API route that still returns JSON; a proxy in front of GitLab returning its own JSON object (e.g. an auth portal); a GitLab version whose endpoint shape differs; an error object like {"message":"..."} delivered with 200.

Common situations: Base URL including a trailing path segment that breaks routing; self-hosted GitLab behind SSO gateways; apiBase pointing at the web UI instead of the API host.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/0b2affe41190c2a8. Report an issue: GitHub.