{"record":{"id":"21d4c54dd0ca5181","repo":"hmjz100/LinkSwift","slug":"url-21d4c5","errorCode":null,"errorMessage":"[天翼云盘] 获取文件 URL 失败","messagePattern":"\\[天翼云盘\\] 获取文件 URL 失败","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":7394,"sourceCode":"\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\n\t\t\t\t\t\t\t$doc.find(\".loading-popup .swal2-html-container\").html(`<div>已获取 ${proc} / ${selects.length} 个链接~</div>`);\r\n\t\t\t\t\t\t\treturn val;\r\n\t\t\t\t\t\t}));\r\n\t\t\t\t});\r\n\t\t\t\tconst res = await Promise.all(queue).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\tres.forEach(val => {\r\n\t\t\t\t\tselects[val.index].downloadUrl = val.downloadUrl;\r\n\t\t\t\t});\r\n\t\t\t\tawait base.sleep(1000);\r\n\t\t\t}\r\n\t\t\ttemp.links = [selects, {\r\n\t\t\t\tisFolder: v => v.isFolder,\r\n\t\t\t\tgetFileName: v => v.fileName,\r\n\t\t\t\tgetFileSize: v => v.size,\r\n\t\t\t\tgetFileLink: v => v.downloadUrl,\r\n\t\t\t\ttooltip: config.$mcloud.dom\r\n\t\t\t}];\r\n\t\t\tbase.showMainDialog(config.base.dom.button[temp.mode].title, base.generateDOM(temp.links), config.base.dom.button[temp.mode].footer);\r\n\t\t},\r\n\t\tgetSelectedList() {\r\n\t\t\ttry {\r\n\t\t\t\treturn document.querySelector(\".c-file-list\").__vue__.selectedList;\r","sourceCodeStart":7376,"sourceCodeEnd":7412,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L7376-L7412","documentation":"A wrapper error thrown in the 天翼云盘 (Tianyi Cloud) getLink batch flow when a per-file getFileUrl promise rejects with a non-Error value. The catch handler re-wraps whatever rejection value it received (or a plain string) into a standardized Error with the message '[天翼云盘] 获取文件 URL 失败' so downstream UI code can display a uniform failure message. It is a normalization wrapper, not the root cause itself.","triggerScenarios":"Batch download link retrieval in getLink(): Promise.all(queue) rejects with a non-Error rejection value — e.g. getFileUrl threw a plain string, an object like {message}, or undefined/null — during processing of a batch of up to 15 selected files via the Tianyi API.","commonSituations":"Expired or invalid Tianyi login session causing underlying getFileUrl to reject with a raw server response object; network timeouts returning non-Error values; API response shape changes after a cloud-side update; selecting files whose share/download permission was revoked mid-batch.","solutions":["Re-login to 天翼云盘 in the userscript so credentials/captcha tokens are refreshed, then retry link fetching","Inspect the console for the original rejection value logged before the wrapper replaces it, and address that root cause","Retry with fewer files selected to isolate which specific file(s) fail and exclude them","Update the userscript if the cloud API contract changed; ensure getFileUrl always throws Error instances so the real message is preserved"],"exampleFix":"// before (anywhere in the flow)\nreject({ code: 500 });\n// after\nreject(new Error(\"获取下载地址失败: \" + JSON.stringify({ code: 500 })));","handlingStrategy":"try-catch","validationCode":"// before getLink\nconst ready = await isTianyiLoggedIn();\nif (!ready) { promptLogin(); return; }","typeGuard":"function isError(e) { return e instanceof Error; }","tryCatchPattern":"try { await getLink(); } catch (e) { if (/天翼云盘.*获取文件 URL 失败/.test(e.message)) { showToast('部分文件链接获取失败，请重新登录天翼云盘后重试'); } else throw e; }","preventionTips":["Re-login when sessions are stale","Select fewer files per batch to limit blast radius","Always throw Error instances in underlying fetch helpers","Log original rejections before wrapping"],"tags":["network","userscript","cloud-drive","error-wrapping"],"backgroundTag":"non-error-rejection","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}