{"record":{"id":"5981a0055b3edf31","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-fetch-documents-from-paperless-ngx-er","errorCode":null,"errorMessage":"Failed to fetch documents from Paperless-ngx: ${error.message}","messagePattern":"Failed to fetch documents from Paperless-ngx: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"collector/utils/extensions/PaperlessNgx/PaperlessNgxLoader/index.js","lineNumber":81,"sourceCode":"        }\n      }\n\n      console.log(\n        `Fetched ${documents.length} documents from Paperless-ngx (Pages: ${\n          page - 1\n        })`\n      );\n\n      const documentsWithContent = await Promise.all(\n        documents.map(async (doc) => {\n          const content = await this.fetchDocumentContent(doc.id);\n          return { ...doc, content };\n        })\n      );\n\n      return documentsWithContent.filter((doc) => !!doc.content);\n    } catch (error) {\n      throw new Error(\n        `Failed to fetch documents from Paperless-ngx: ${error.message}`\n      );\n    }\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      );","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/collector/utils/extensions/PaperlessNgx/PaperlessNgxLoader/index.js#L63-L99","documentation":"Outer catch in fetchAllDocuments — wraps any error that escaped the inner per-page handling (e.g. an error thrown while resolving document content via Promise.all, or a non-fetch programming error). The inner page errors are swallowed, so this usually originates from fetchDocumentContent or array processing.","triggerScenarios":"An exception propagates from the documents-with-content Promise.all or another uncaught path inside fetchAllDocuments; the inner per-page try/catch does not cover this stage.","commonSituations":"fetchDocumentContent throwing despite its own catch (unusual), an unexpected response shape (no results array), or a programming error in the map.","solutions":["Inspect error.message — it is the wrapped inner cause.","Note fetchDocumentContent normally swallows its own errors and returns \"\", so a propagated error is unusual.","Validate the documents response shape (results array, next, etc.) before processing."],"exampleFix":"// before\nthrow new Error(`Failed to fetch documents from Paperless-ngx: ${error.message}`);\n\n// after — preserve the cause and original stack\nconst wrapped = new Error(`Failed to fetch documents from Paperless-ngx: ${error.message}`);\nwrapped.cause = error;\nthrow wrapped;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { const docs = await loader.load(); }\ncatch (e) {\n  if (e.message.startsWith(\"Failed to fetch documents from Paperless-ngx:\")) {\n    /* inspect inner cause — likely content fetch or response-shape error */\n  }\n  throw e;\n}","preventionTips":["Validate the API response shape before processing.","Keep fetchDocumentContent defensive (it already returns '').","Preserve the inner cause when wrapping errors."],"tags":["paperless-ngx","http","integration","error-wrapping"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}