{"record":{"id":"e23c8ec6512cd477","repo":"hmjz100/LinkSwift","slug":"error-e23c8e","errorCode":null,"errorMessage":"[天翼云盘] 获取令牌失败","messagePattern":"\\[天翼云盘\\] 获取令牌失败","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":7369,"sourceCode":"\t\t\t\treturn { index, downloadUrl: res.fileDownloadUrl };\r\n\t\t\t} else if (res.errorcode == \"InvalidSessionKey\") {\r\n\t\t\t\treturn { index, downloadUrl: \"提示：<br/>请先登录网盘~\" };\r\n\t\t\t} else if (res.res_code == \"ShareNotFoundFlatDir\") {\r\n\t\t\t\treturn { index, downloadUrl: \"提示：<br/>请[转存]文件，之后再👉前往[我的网盘]中下载哦~\" };\r\n\t\t\t} else {\r\n\t\t\t\treturn { index, downloadUrl: \"获取下载地址失败，刷新后再试试吧~\" + (res.res_code ? res.res_code : \"\") };\r\n\t\t\t}\r\n\t\t},\r\n\t\tasync getLink() {\r\n\t\t\tlet selects = this.getSelectedList();\r\n\t\t\tif (selects.length === 0) throw new Error(\"提示：<br/>请勾选要下载的文件哦~\");\r\n\t\t\tif (selects.every(item => item.isFolder)) throw new Error(\"提示：<br/>请打开文件夹后再勾选文件~\");\r\n\t\t\tselects = selects.filter(item => !item.isFolder)\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\t\t\tconst token = base.getStorage(\"accessToken\") || await this.getToken().catch(e => {\r\n\t\t\t\tif (e instanceof Error) throw e;\r\n\t\t\t\tthrow new Error(e?.message || e || \"[天翼云盘] 获取令牌失败\");\r\n\t\t\t});\r\n\t\t\tif (!token) {\r\n\t\t\t\tthrow new Error(\"提示：<br/>请先登录网盘~\");\r\n\t\t\t}\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\t\t\tconst batchSize = 15;\r\n\t\t\tlet proc = 0;\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\t\t\tfor (let i = 0; i < selects.length; i += batchSize) {\r\n\t\t\t\tconst batch = selects.slice(i, i + batchSize);\r\n\t\t\t\tconst queue = [];\r\n\t\t\t\tbatch.forEach((item, localIndex) => {\r\n\t\t\t\t\tconst globalIndex = i + localIndex;\r\n\t\t\t\t\tqueue.push(this.getFileUrl(item, globalIndex, token)\r\n\t\t\t\t\t\t.then(val => {\r\n\t\t\t\t\t\t\tproc++;\r","sourceCodeStart":7351,"sourceCodeEnd":7387,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L7351-L7387","documentation":"Fallback error when getToken() for 天翼云盘 rejects with a non-Error value. The script first tries the cached accessToken from storage; if absent, it calls getToken(), and if that promise rejects with something that isn't an Error instance (string/object/undefined), it is rewrapped as this generic '[天翼云盘] 获取令牌失败' message.","triggerScenarios":"base.getStorage(\"accessToken\") is empty AND this.getToken() rejects with a non-Error value whose ?message is falsy, in the catch at line 7369.","commonSituations":"User not logged into 天翼云盘 so token acquisition fails; the login-session cookie expired; the token API returned an unexpected body (captcha, risk-control page) that was rejected raw; network failure during token fetch.","solutions":["Log in to 天翼云盘 in the same browser, then refresh the page and retry.","Clear the script's stored accessToken and re-trigger token acquisition while logged in.","Inspect the raw rejection value inside getToken() to see the actual API response (e.g. captcha or risk-control) and handle it.","Update the userscript if the site changed its login/token endpoint."],"exampleFix":"// before\nthrow e?.message || e;\n\n// after\nconst detail = e?.message ?? (typeof e === 'object' ? JSON.stringify(e) : String(e));\nthrow new Error('[天翼云盘] 获取令牌失败: ' + detail);","handlingStrategy":"try-catch","validationCode":"if (!base.getStorage('accessToken') && !isLoggedInToTianyi()) {\n  alert('请先登录天翼云盘~');\n  return;\n}","typeGuard":"function isUsableToken(t) {\n  return typeof t === 'string' && t.length > 0;\n}","tryCatchPattern":"try {\n  var token = base.getStorage('accessToken') || await getToken();\n} catch (e) {\n  console.error('getToken原始失败:', e);\n  throw new Error('[天翼云盘] 获取令牌失败: ' + (e?.message ?? String(e)));\n}","preventionTips":["Log in to 天翼云盘 before running downloads; keep the session cookie alive.","Log the raw rejection inside getToken() to catch captcha/risk-control responses.","Clear the cached accessToken after logging out so stale tokens aren't reused.","Update the userscript after site login-flow changes."],"tags":["userscript","tianyi-cloud","auth","token-acquisition"],"backgroundTag":"token-acquisition-failed","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}