{"record":{"id":"9f426d44e2c9ef63","repo":"hmjz100/LinkSwift","slug":"br-9f426d","errorCode":null,"errorMessage":"提示：<br/>请先登录网盘后再刷新页面呢~","messagePattern":"提示：<br/>请先登录网盘后再刷新页面呢~","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":8093,"sourceCode":"\t\t\t\tlet res;\r\n\t\t\t\tif (item.downloadUrl) return { index, downloadUrl: item.downloadUrl };\r\n\t\t\t\tif (shareToken) {\r\n\t\t\t\t\tres = await base.post(config.$guangya.api.getShareLink, { \"fileId\": item.fileId, \"accessToken\": shareToken }, { \"Authorization\": `${token.credentials?.token_type} ${token.credentials?.access_token}`, \"Content-Type\": \"application/json\", \"X-Captcha-Token\": token.captcha.captcha_token, \"X-Device-Id\": token.deviceid });\r\n\t\t\t\t} else {\r\n\t\t\t\t\tres = await base.post(config.$guangya.api.getLink, { \"fileId\": item.fileId }, { \"Authorization\": `${token.credentials?.token_type} ${token.credentials?.access_token}`, \"Content-Type\": \"application/json\", \"X-Captcha-Token\": token.captcha.captcha_token, \"X-Device-Id\": token.deviceid });\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (res.data?.signedURL || res.data?.downloadUrl) {\r\n\t\t\t\t\treturn { index, downloadUrl: res.data?.signedURL ?? res.data?.downloadUrl };\r\n\t\t\t\t} else if (res.code) {\r\n\t\t\t\t\tif (res.code == 9) return { index, downloadUrl: \"获取下载地址失败，服务器说：页面验证过期了，刷新后再获取吧~\" };\r\n\t\t\t\t\tif (res.code == 103) return { index, downloadUrl: \"获取下载地址失败，服务器说：后端 RPC 响应超时。脚本建议：再重新获取一次~\" };\r\n\t\t\t\t\tif (res.code == 207) return { index, downloadUrl: \"获取下载地址失败，服务器说：分享者未打开免登录下载。请登录后下载~\" };\r\n\t\t\t\t} else {\r\n\t\t\t\t\treturn { index, downloadUrl: `获取下载地址失败，${res.msg ? \"服务器说：\" + res.msg + \"。\" : \"刷新后再试试吧~\"}` };\r\n\t\t\t\t}\r\n\t\t\t} catch {\r\n\t\t\t\tthrow new Error(\"提示：<br/>请先登录网盘后再刷新页面呢~\");\r\n\t\t\t}\r\n\t\t},\r\n\t\tasync getLink() {\r\n\t\t\tconst selects = this.getSelectedList();\r\n\t\t\tif (selects.length === 0) throw new Error(\"提示：<br/>请勾选要下载的文件哦~\");\r\n\t\t\tif (selects.every(item => item.resType == 2)) throw new Error(\"提示：<br/>请打开文件夹后再勾选文件~\");\r\n\t\t\tif (temp.page === \"home\") {\r\n\t\t\t\tconst token = this.getToken();\r\n\t\t\t\tconst batchSize = 15;\r\n\t\t\t\tlet proc = 0;\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\t\t\t\tfor (let i = 0; i < selects.length; i += batchSize) {\r\n\t\t\t\t\tconst batch = selects.slice(i, i + batchSize);\r\n\t\t\t\t\tconst queue = [];\r\n\t\t\t\t\tbatch.forEach((item, localIndex) => {\r\n\t\t\t\t\t\tconst globalIndex = i + localIndex;\r\n\t\t\t\t\t\tqueue.push(this.getFileUrl(item, globalIndex, token)\r","sourceCodeStart":8075,"sourceCodeEnd":8111,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L8075-L8111","documentation":"This userscript (网盘直链下载助手, 光鸭云盘 driver) throws this when the RPC/backend request inside getLink() throws a non-Error value in its try/catch. The catch block assumes the most common cause is an unauthenticated session (network disk cookies missing/expired), so it converts any thrown failure into a 'please log in first' hint. It is a user-facing hint rather than a precise diagnostic.","triggerScenarios":"The await-ed backend call in the link-fetch flow throws (network failure, invalid JSON, 401/redirect to login page returning non-JSON, GM_xmlhttpRequest error) and the caught value is not an Error with res.code 103/207; the catch{} unconditionally throws this login hint.","commonSituations":"User's cloud-drive cookie expired or they opened a share page without logging in; backend RPC returned non-JSON (login redirect HTML) causing JSON.parse throw; network blocked the request entirely.","solutions":["Log in to the cloud-drive website in the same browser, confirm you can browse files, then retry.","Refresh the page so the script picks up fresh cookies, then re-fetch links.","If already logged in, check the network/console for the real underlying request failure (timeout, CORS, blocked RPC) before assuming auth.","Clear stale cookies or re-login if the session is half-expired."],"exampleFix":"// before\ncatch {\n  throw new Error(\"提示：<br/>请先登录网盘后再刷新页面呢~\");\n}\n// after\ncatch (e) {\n  if (e instanceof Error && /login|401/i.test(String(e.message))) throw new Error(\"提示：<br/>请先登录网盘后再刷新页面呢~\");\n  throw new Error(\"获取失败：\" + (e?.message || e));\n}","handlingStrategy":"try-catch","validationCode":"// run before fetching\nconst loggedOut = !document.cookie || !/^(?:.*;)?\\s*(__pus|__puer)=/.test(document.cookie);\nif (loggedOut) alert('请先登录网盘');","typeGuard":"function is thrownValueError(e) { return e instanceof Error; }","tryCatchPattern":"try { await driver.getLink(); } catch (e) { if (String(e.message).includes('请先登录网盘')) { promptLogin(); } else { throw e; } }","preventionTips":["Log in to the cloud drive before using the script","Refresh after login so cookies are picked up","Watch the console for the real underlying request failure"],"tags":["userscript","auth","cloud-drive","session-expired"],"backgroundTag":"not-logged-in-cloud-drive","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}