{"record":{"id":"77ba930890b9567a","repo":"hmjz100/LinkSwift","slug":"url","errorCode":null,"errorMessage":"[百度网盘] 获取文件 URL 失败","messagePattern":"\\[百度网盘\\] 获取文件 URL 失败","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":6105,"sourceCode":"\t\t\t// 获取选择的文件列表\r\n\t\t\tconst selects = this.getSelectedList();\r\n\t\t\tif (selects.length === 0) throw new Error(\"提示：<br/>请勾选要下载的文件哦~\");\r\n\r\n\t\t\t$doc.find(\".loading-popup .loading-title\").html(`链接获取中`);\r\n\t\t\t$doc.find(\".loading-popup .swal2-html-container\").html(`<div>正在获取文件对应的下载链接~</div>`);\r\n\r\n\t\t\tlet files = selects.filter(f => !f.isdir);\r\n\t\t\tconst dirs = selects.filter(f => f.isdir);\r\n\t\t\tif (temp.page === \"home\" || temp.page === \"main\") {\r\n\t\t\t\tif (dirs.length > 0) files = files.concat(await this.getFilesList(dirs, token, files.length));\r\n\t\t\t\tif (!files.length) throw new Error(\"提示：<br/>文件夹是空的哦~\");\r\n\r\n\t\t\t\t$doc.find(\".loading-popup .loading-title\").html(`链接获取中`);\r\n\t\t\t\t$doc.find(\".loading-popup .swal2-html-container\").html(`<div>正在获取文件对应的下载链接~</div>`);\r\n\r\n\t\t\t\tfiles = await this.getFilesUrl(files, token).catch(e => {\r\n\t\t\t\t\tif (e instanceof Error) throw e;\r\n\t\t\t\t\tthrow new Error(e?.message || e || \"[百度网盘] 获取文件 URL 失败\");\r\n\t\t\t\t});\r\n\t\t\t} else if (temp.page === \"share\") {\r\n\t\t\t\tconst shareData = await this.getShareData();\r\n\r\n\t\t\t\tconst sign = await base.get(`${config.$baidu.api.getShareSign}&surl=1${shareData.share.url}$bdstoken=${shareData.baidu.token}&logid=${base.encodeBase(shareData.baidu.id)}`);\r\n\t\t\t\tif (sign?.data?.sign && sign?.data?.timestamp) {\r\n\t\t\t\t\tshareData.sign = sign.data.sign;\r\n\t\t\t\t\tshareData.timestamp = sign.data.timestamp;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tfiles = await this.getShareFilesUrl(files, shareData, token).catch(e => {\r\n\t\t\t\t\tif (e instanceof Error) throw e;\r\n\t\t\t\t\tthrow new Error(e?.message || e || \"[百度网盘] 获取分享文件 URL 失败\");\r\n\t\t\t\t});\r\n\t\t\t} else {\r\n\t\t\t\tthrow new Error(\"提示：<br/>页面错误~\");\r\n\t\t\t}\r\n\r","sourceCodeStart":6087,"sourceCodeEnd":6123,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L6087-L6123","documentation":"Fallback error thrown in the .catch() of `this.getFilesUrl(files, token)` for the Baidu Netdisk page (home/main). If the underlying rejection is not an Error instance (e.g. a plain string, object, or undefined from a failed fetch/XHR), it is re-wrapped with this generic message; the original message is used when the thrown value has a `message` property.","triggerScenarios":"getFilesUrl's internal HTTP requests to Baidu's download-link API fail or reject with a non-Error value: expired/invalid access token, API endpoint change, rate limiting, or network failure returning a non-Error rejection.","commonSituations":"Stale token in script storage after logging out/in; Baidu API change breaking the userscript after a Netdisk frontend update; network blocked or Baidu risk-control rejecting rapid link requests; cookie/BDUSS missing so the dlink API returns an HTML error page.","solutions":["Log out and back into Baidu Netdisk, then re-save the token in the script settings to refresh credentials.","Update the userscript to the latest version to pick up API endpoint fixes.","Retry after a wait — Baidu rate-limits/risk-controls frequent link fetches.","Open DevTools Network tab to inspect the actual failed request and response for the real cause."],"exampleFix":"// before\nthrow new Error(e?.message || e || \"[百度网盘] 获取文件 URL 失败\");\n// after\nconst raw = e?.responseText || e?.message || e;\nconsole.error(\"getFilesUrl failed:\", raw); // surface the true upstream cause","handlingStrategy":"try-catch","validationCode":"const token = base.getStorage('token');\nif (!token || !token.access_token) { alert('请先登录网盘并刷新 token'); return; }","typeGuard":"function isHttpError(e) { return e instanceof Error || (e && typeof e.message === 'string'); }","tryCatchPattern":"try { await getLinks(); } catch (e) { const cause = e && e.cause ? e.cause : e; console.error('Baidu link fetch failed:', cause); if (/401|token/i.test(String(cause))) refreshBaiduToken(); }","preventionTips":["Refresh your Baidu Netdisk token regularly; re-login when links start failing","Keep the userscript updated for API endpoint changes","Avoid rapid repeated link fetches to dodge rate limiting","Check DevTools Network for the upstream failure before guessing"],"tags":["userscript","baidu-netdisk","network","api","token"],"backgroundTag":"api-request-failed","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}