Mintplex-Labs/anything-llm · error · Error
Failed to fetch documents from Paperless-ngx: ${res.status}
Error message
Failed to fetch documents from Paperless-ngx: ${res.status} What it means
PaperlessNgxLoader.fetchAllDocuments throws (inside a per-page try) when the documents list endpoint returns non-ok. The inner try/catch logs and breaks the pagination loop rather than propagating, so a failed page stops further fetching but does not crash the call.
Source
Thrown at collector/utils/extensions/PaperlessNgx/PaperlessNgxLoader/index.js:43
* @returns {Promise<{{[key: string]: any, content: string}[]}>} The documents with their content
*/
async fetchAllDocuments() {
try {
const documents = [];
let nextUrl = `${this.baseUrl}/api/documents/`;
let page = 1;
while (nextUrl) {
console.log(`Fetching documents page ${page} from Paperless-ngx`);
try {
const data = await fetch(nextUrl, {
headers: {
"Content-Type": "application/json",
...this.baseHeaders,
},
}).then((res) => {
if (!res.ok)
throw new Error(
`Failed to fetch documents from Paperless-ngx: ${res.status}`
);
return res.json();
});
const validResults = data.results.filter((doc) => doc?.id);
if (!validResults.length) break;
documents.push(...validResults);
if (data.next === nextUrl) break;
nextUrl = data.next || null;
page++;
} catch (error) {
console.error(
`Error fetching page ${page} from Paperless-ngx:`,
error
);View on GitHub (pinned to 526360e320)
Solutions
- Confirm the token: `curl -H "Authorization: Token <token>" <baseUrl>/api/documents/`.
- Verify baseUrl.origin is correct (the constructor strips to origin).
- Check the logged status code in the per-page error.
- Ensure the token has document read permissions.
Example fix
// before
if (!res.ok) throw new Error(`Failed to fetch documents from Paperless-ngx: ${res.status}`);
// after — include status text + the page being fetched
if (!res.ok) throw new Error(`Paperless-ngx ${res.status} ${res.statusText} on page ${page} (${nextUrl})`); Defensive patterns
Strategy: try-catch
Validate before calling
async function paperlessAuthOk(baseUrl, token) {
const r = await fetch(`${new URL(baseUrl).origin}/api/documents/?page_size=1`, {
headers: { Authorization: `Token ${token}` },
});
return r.ok;
} Try / catch
// fetchAllDocuments swallows per-page errors and breaks the loop
const docs = await loader.fetchAllDocuments();
if (docs.length === 0) { /* check logs for "Failed to fetch documents from Paperless-ngx: <status>" */ } Prevention
- Use the 'Token' scheme, not 'Bearer', for Paperless-ngx.
- Pre-validate the token with a one-item request.
- Watch the per-page error logs — they do not throw.
When it happens
Trigger: GET /api/documents/ returns non-2xx: 401 (bad apiToken — note the "Token <token>" scheme, not Bearer), 403, 404 (wrong baseUrl), 5xx.
Common situations: Wrong apiToken; baseUrl pointing to the wrong origin (the constructor strips to origin); Paperless-ngx API path changed; token lacks read permissions.
Related errors
- Failed to fetch ${url} from Confluence: ${response.status}
- Failed to fetch ${url}: ${response.status}
- Failed to fetch documents from Paperless-ngx: ${error.messag
- Failed to fetch document content: ${response.status}
- Failed to fetch document content
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/eee6c146132ad13a.
Report an issue: GitHub.