Mintplex-Labs/anything-llm · warning · Error

Failed to fetch document content: ${response.status}

Error message

Failed to fetch document content: ${response.status}

What it means

fetchDocumentContent throws when the document download endpoint (/api/documents/<id>/download/) returns non-ok. The method's own catch logs the error and returns "" — so this message appears in logs but the exception does not propagate; the document is treated as having empty content and filtered out.

Source

Thrown at collector/utils/extensions/PaperlessNgx/PaperlessNgxLoader/index.js:102

    }
  }

  /**
   * Fetches the content of a document from Paperless-ngx
   * @param {string} documentId - The ID of the document to fetch
   * @returns {Promise<string>} The content of the document
   */
  async fetchDocumentContent(documentId) {
    try {
      const response = await fetch(
        `${this.baseUrl}/api/documents/${documentId}/download/`,
        {
          headers: this.baseHeaders,
        }
      );

      if (!response.ok)
        throw new Error(`Failed to fetch document content: ${response.status}`);

      const contentType = response.headers.get("content-type");
      switch (contentType) {
        case "text/plain":
          return await response.text();
        case "application/pdf":
          const buffer = await response.arrayBuffer();
          return await this.parsePdfContent(buffer);
        default:
          return await response.text();
      }
    } catch (error) {
      console.error(
        `Failed to fetch content for document ${documentId}:`,
        error
      );
      return "";
    }

View on GitHub (pinned to 526360e320)

Solutions

  1. Check the logged status for the specific documentId.
  2. Confirm the token has download permissions.
  3. Treat empty content as 'skip' — the loader already filters these out.

Example fix

// before
if (!response.ok) throw new Error(`Failed to fetch document content: ${response.status}`);

// after — distinguish 404 (gone) from other failures
if (!response.ok) {
  if (response.status === 404) return ""; // document no longer exists
  throw new Error(`Document ${documentId} content fetch ${response.status}`);
}
Defensive patterns

Strategy: try-catch

Try / catch

// fetchDocumentContent already catches and returns "" — callers see empty content
const content = await loader.fetchDocumentContent(id);
if (!content) { /* document skipped; check logs for the status */ }

Prevention

When it happens

Trigger: Download endpoint returns non-2xx: 404 (doc deleted between list and download), 403 (permissions), 5xx, or a content-type the switch does not handle.

Common situations: Document deleted between listing and download; token lacks download permissions; large-file timeout; corrupted document.

Related errors


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