{"record":{"id":"c63147e0b76c5ed0","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-fetch-document-content-response-statu","errorCode":null,"errorMessage":"Failed to fetch document content: ${response.status}","messagePattern":"Failed to fetch document content: (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"collector/utils/extensions/PaperlessNgx/PaperlessNgxLoader/index.js","lineNumber":102,"sourceCode":"    }\n  }\n\n  /**\n   * Fetches the content of a document from Paperless-ngx\n   * @param {string} documentId - The ID of the document to fetch\n   * @returns {Promise<string>} The content of the document\n   */\n  async fetchDocumentContent(documentId) {\n    try {\n      const response = await fetch(\n        `${this.baseUrl}/api/documents/${documentId}/download/`,\n        {\n          headers: this.baseHeaders,\n        }\n      );\n\n      if (!response.ok)\n        throw new Error(`Failed to fetch document content: ${response.status}`);\n\n      const contentType = response.headers.get(\"content-type\");\n      switch (contentType) {\n        case \"text/plain\":\n          return await response.text();\n        case \"application/pdf\":\n          const buffer = await response.arrayBuffer();\n          return await this.parsePdfContent(buffer);\n        default:\n          return await response.text();\n      }\n    } catch (error) {\n      console.error(\n        `Failed to fetch content for document ${documentId}:`,\n        error\n      );\n      return \"\";\n    }","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/collector/utils/extensions/PaperlessNgx/PaperlessNgxLoader/index.js#L84-L120","documentation":"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.","triggerScenarios":"Download endpoint returns non-2xx: 404 (doc deleted between list and download), 403 (permissions), 5xx, or a content-type the switch does not handle.","commonSituations":"Document deleted between listing and download; token lacks download permissions; large-file timeout; corrupted document.","solutions":["Check the logged status for the specific documentId.","Confirm the token has download permissions.","Treat empty content as 'skip' — the loader already filters these out."],"exampleFix":"// before\nif (!response.ok) throw new Error(`Failed to fetch document content: ${response.status}`);\n\n// after — distinguish 404 (gone) from other failures\nif (!response.ok) {\n  if (response.status === 404) return \"\"; // document no longer exists\n  throw new Error(`Document ${documentId} content fetch ${response.status}`);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// fetchDocumentContent already catches and returns \"\" — callers see empty content\nconst content = await loader.fetchDocumentContent(id);\nif (!content) { /* document skipped; check logs for the status */ }","preventionTips":["Expect some documents to fail download; the loader filters empties.","Log documentId alongside the status for triage.","Do not treat an empty content result as a fatal error."],"tags":["paperless-ngx","http","integration","content-fetch"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}