{"record":{"id":"d5353375f528f55e","repo":"hmjz100/LinkSwift","slug":"br-br-res-code-res-code","errorCode":null,"errorMessage":"提示：<br/>获取链接失败了~<br/>${res.code ? res.code : \"\"} ${res.message ? res.message : \"\"}","messagePattern":"提示：<br/>获取链接失败了~<br/>(.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":8500,"sourceCode":"\t\t\t\tlet proc = 0;\r\n\t\t\t\tselects = selects.filter(item => item.file === true)\r\n\t\t\t\tfor (let i = 0; i < selects.length; i += batchSize) {\r\n\t\t\t\t\t// 获取当前批次文件\r\n\t\t\t\t\tconst batch = selects.slice(i, i + batchSize);\r\n\t\t\t\t\tconst fids = batch.map(item => item.fid);\r\n\t\t\t\t\t// 发起请求获取链接\r\n\t\t\t\t\tconst res = await base.post(config.$quark.api.getLink, { \"fids\": fids }, { \"Content-Type\": \"application/json\", \"Cookie\": String(document.cookie), \"User-Agent\": config.$quark.api.ua.downloadLink });\r\n\r\n\t\t\t\t\tif (!res || res.code !== 0 || !res.data) {\r\n\t\t\t\t\t\tif (res.code == 31001) throw new Error(\"提示：<br/>请先登录网盘~<br/>代码：\" + res.code);\r\n\t\t\t\t\t\tif (res.code == 23018) {\r\n\t\t\t\t\t\t\tconst fid = res.message?.match(/\\[([a-f0-9]{32})\\]/)?.[1];\r\n\t\t\t\t\t\t\tconst item = batch.find(item => item.fid === fid);\r\n\t\t\t\t\t\t\tthrow new Error(`提示：<br/>超出游客可获取大小限制<br/>请登录后获取哦~${item?.file_name ? `<br/>文件：${item.file_name}` : \"\"}`);\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (res.code || res.message) {\r\n\t\t\t\t\t\t\tthrow new Error(`提示：<br/>获取链接失败了~<br/>${res.code ? res.code : \"\"} ${res.message ? res.message : \"\"}`);\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tthrow new Error(\"提示：<br/>获取下载链接失败，刷新网页后再试试吧~\");\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// 合并响应数据\r\n\t\t\t\t\tif (res.data) {\r\n\t\t\t\t\t\tdata.push(...res.data);\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// 更新处理进度\r\n\t\t\t\t\tproc += batch.length;\r\n\t\t\t\t\t// 更新UI显示\r\n\t\t\t\t\t$doc.find(\".loading-popup .loading-title\").html(`链接获取中`);\r\n\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// 请求间隔节流\r\n\t\t\t\t\tawait base.sleep(1000);\r\n\t\t\t\t}\r\n\t\t\t\ttemp.links = [data, {\r","sourceCodeStart":8482,"sourceCodeEnd":8518,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L8482-L8518","documentation":"Generic failure branch of the Quark share-page link fetch: the API returned a non-zero code (or missing data) that was not the specifically handled 31001/23018 cases. The script surfaces the raw code and message from the API response so the developer can see what Quark rejected. It is a catch-all for any unclassified getLink API error.","triggerScenarios":"base.post(config.$quark.api.getLink, ...) on the share page returns res with res.code !== 0 (and code is not 31001 or 23018) but res.code or res.message is set — e.g. expired share stoken, revoked share, rate limiting, or API change.","commonSituations":"Share link was cancelled or expired server-side; stoken invalid for the batch; Quark API endpoint changed or requires new params; request blocked by network/proxy returning an error JSON.","solutions":["Read the code/message in the error text and look it up in Quark's API codes","Re-open the share page to get a fresh stoken/pwd_id, then retry","Confirm the share is still valid and files still exist","Clear cookies and log in again in case of stale session state"],"exampleFix":"// before\nthrow new Error(`提示：<br/>获取链接失败了~<br/>${res.code ? res.code : \"\"} ${res.message ? res.message : \"\"}`);\n// after\nif (res.code === 41011) throw new Error(\"分享已取消或失效，请重新打开分享页\");\nthrow new Error(`提示：<br/>获取链接失败了~<br/>${res.code ?? \"\"} ${res.message ?? \"\"}`);","handlingStrategy":"try-catch","validationCode":"const res = await base.post(cfg.$quark.api.getLink, payload, headers); if (!res || typeof res.code !== 'number') throw new Error('非JSON响应');","typeGuard":"function isQuarkLinkRes(r){ return r && typeof r === 'object' && typeof r.code === 'number'; }","tryCatchPattern":"try { await getLink(...) } catch (e) { const m = String(e.message).match(/获取链接失败了~\\s*(\\d*)\\s*(.*)/); if (m) console.error('quark api code', m[1], m[2]); retryWithFreshStoken(); }","preventionTips":["Refresh the share page before exporting to get a fresh stoken","Confirm the share is still valid (not cancelled/expired)","Keep the userscript updated against Quark API changes","Inspect the returned code in devtools when it recurs"],"tags":["userscript","quark-netdisk","api-error","unclassified"],"backgroundTag":"upstream-api-error","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}