{"record":{"id":"f4a63f8c69b0c930","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-fetch-url-response-status","errorCode":null,"errorMessage":"Failed to fetch ${url}: ${response.status}","messagePattern":"Failed to fetch (.+?): (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"collector/utils/extensions/DrupalWiki/DrupalWiki/index.js","lineNumber":240,"sourceCode":"  #generateChunkSource(pageId, encryptionWorker) {\n    const payload = {\n      baseUrl: this.baseUrl,\n      pageId: pageId,\n      accessToken: this.accessToken,\n    };\n    return `drupalwiki://${\n      this.baseUrl\n    }/node/${pageId}?payload=${encryptionWorker.encrypt(\n      JSON.stringify(payload)\n    )}`;\n  }\n\n  async _doFetch(url) {\n    const response = await fetch(url, {\n      headers: this.#getHeaders(),\n    });\n    if (!response.ok) {\n      throw new Error(`Failed to fetch ${url}: ${response.status}`);\n    }\n    return response.json();\n  }\n\n  #getHeaders() {\n    return {\n      \"Content-Type\": \"application/json\",\n      Accept: \"application/json\",\n      Authorization: `Bearer ${this.accessToken}`,\n    };\n  }\n\n  #prepareStoragePath(baseUrl) {\n    const { hostname } = new URL(baseUrl);\n    const subFolder = slugify(`drupalwiki-${hostname}`).toLowerCase();\n    const outFolder = path.resolve(documentsFolder, subFolder);\n    if (!fs.existsSync(outFolder)) fs.mkdirSync(outFolder, { recursive: true });\n    return outFolder;","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/collector/utils/extensions/DrupalWiki/DrupalWiki/index.js#L222-L258","documentation":"DrupalWiki._doFetch throws on any non-ok response. It is used by page-index listing, single-page fetch, and attachment listing. Unlike Confluence there is no outer try/catch here — the error propagates directly to the caller.","triggerScenarios":"DrupalWiki REST API returns non-2xx: 401 (bad accessToken), 403, 404 (wrong spaceId/pageId), 5xx, or a changed API path.","commonSituations":"Wrong/expired access token; baseUrl mismatch; spaceId does not exist; the Scope/DrupalWiki API plugin path changed between versions.","solutions":["Verify accessToken and baseUrl with a GET to /api/rest/scope/api/page?size=1&space=<id>.","Confirm the spaceId exists for that instance.","Check the status code embedded in the message.","Ensure the DrupalWiki Scope API plugin is installed and the path matches."],"exampleFix":"// before\nif (!response.ok) throw new Error(`Failed to fetch ${url}: ${response.status}`);\n\n// after — surface status text + handle 401 distinctly\nif (!response.ok) {\n  if (response.status === 401) throw new Error(`DrupalWiki auth failed for ${url}`);\n  throw new Error(`DrupalWiki ${response.status} ${response.statusText} for ${url}`);\n}","handlingStrategy":"try-catch","validationCode":"async function drupalAuthOk(baseUrl, token) {\n  const r = await fetch(`${baseUrl}/api/rest/scope/api/page?size=1`, {\n    headers: { Authorization: `Bearer ${token}`, Accept: \"application/json\" },\n  });\n  return r.ok;\n}","typeGuard":null,"tryCatchPattern":"try { await wiki.loadAndStoreAllPagesForSpace(spaceId, enc); }\ncatch (e) {\n  if (/Failed to fetch .*: 401/.test(e.message)) { /* refresh token */ }\n  throw e;\n}","preventionTips":["Validate the token/space before bulk import.","Keep baseUrl consistent with the instance.","Pin to a supported DrupalWiki/Scope API version."],"tags":["drupalwiki","http","integration","auth"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}