hmjz100/LinkSwift · error · Error

提示:<br/>获取链接失败了~<br/>${res.code ? res.code : ""} ${res.messa

Error message

提示:<br/>获取链接失败了~<br/>${res.code ? res.code : ""} ${res.message ? res.message : ""}

What it means

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.

Source

Thrown at (改)网盘直链下载助手.user.js:8500

				let proc = 0;
				selects = selects.filter(item => item.file === true)
				for (let i = 0; i < selects.length; i += batchSize) {
					// 获取当前批次文件
					const batch = selects.slice(i, i + batchSize);
					const fids = batch.map(item => item.fid);
					// 发起请求获取链接
					const 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 });

					if (!res || res.code !== 0 || !res.data) {
						if (res.code == 31001) throw new Error("提示:<br/>请先登录网盘~<br/>代码:" + res.code);
						if (res.code == 23018) {
							const fid = res.message?.match(/\[([a-f0-9]{32})\]/)?.[1];
							const item = batch.find(item => item.fid === fid);
							throw new Error(`提示:<br/>超出游客可获取大小限制<br/>请登录后获取哦~${item?.file_name ? `<br/>文件:${item.file_name}` : ""}`);
						}

						if (res.code || res.message) {
							throw new Error(`提示:<br/>获取链接失败了~<br/>${res.code ? res.code : ""} ${res.message ? res.message : ""}`);
						} else {
							throw new Error("提示:<br/>获取下载链接失败,刷新网页后再试试吧~");
						}
					}

					// 合并响应数据
					if (res.data) {
						data.push(...res.data);
					}
					// 更新处理进度
					proc += batch.length;
					// 更新UI显示
					$doc.find(".loading-popup .loading-title").html(`链接获取中`);
					$doc.find(".loading-popup .swal2-html-container").html(`<div>已获取 ${proc} / ${selects.length} 个链接~</div>`);
					// 请求间隔节流
					await base.sleep(1000);
				}
				temp.links = [data, {

View on GitHub (pinned to 417ea5e28a)

Solutions

  1. Read the code/message in the error text and look it up in Quark's API codes
  2. Re-open the share page to get a fresh stoken/pwd_id, then retry
  3. Confirm the share is still valid and files still exist
  4. Clear cookies and log in again in case of stale session state

Example fix

// before
throw new Error(`提示:<br/>获取链接失败了~<br/>${res.code ? res.code : ""} ${res.message ? res.message : ""}`);
// after
if (res.code === 41011) throw new Error("分享已取消或失效,请重新打开分享页");
throw new Error(`提示:<br/>获取链接失败了~<br/>${res.code ?? ""} ${res.message ?? ""}`);
Defensive patterns

Strategy: try-catch

Validate before calling

const res = await base.post(cfg.$quark.api.getLink, payload, headers); if (!res || typeof res.code !== 'number') throw new Error('非JSON响应');

Type guard

function isQuarkLinkRes(r){ return r && typeof r === 'object' && typeof r.code === 'number'; }

Try / catch

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(); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02). Data as JSON: /api/errors/d5353375f528f55e. Report an issue: GitHub.