hmjz100/LinkSwift · error · Error

112

112

Error message

提示:<br/>页面已过期,请刷新后重试~<br/>代码:112

What it means

Baidu Netdisk's OpenAPI file-list endpoint (fetched via base.get with access_token, 网盘直链下载助手.user.js:5938) returned errno 112. Baidu uses errno 112 to mean the session/page identifier has expired, so the script throws this 'page expired, refresh and retry' error. It is a server-reported staleness code surfaced as a user-facing error.

Source

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

				}

				temp.glinks.splice(idx, 1); // 过期删除
				return true;
			});

			for (let i = 0; i < pending.length; i += size) {
				// 当前批次
				const batch = pending.slice(i, i + size);
				const fsids = JSON.stringify(batch.map(item => item.fs_id));

				const url = new URL(config.$baidu.api.getLink);
				url.searchParams.set("fsids", fsids);
				url.searchParams.set("access_token", token);

				const res = await base.get(url, { "User-Agent": config.$baidu.api.ua.downloadLink });

				if (!res || res.errno !== 0 || !res.list) {
					if (res.errno === 112) throw new Error("提示:<br/>页面已过期,请刷新后重试~<br/>代码:" + res.errno);
					if (res.errno === 9019) {
						base.delValue("baidu_access_token");
						throw new Error("提示:<br/>访问令牌已过期,再获取一次吧~<br/>代码:" + res.errno);
					}
					if (res.errno || res.errmsg) {
						batch.forEach(item => item.dlink = `获取下载地址失败,${(res.errno || res.errmsg) ? "服务器说:" + (res.errno && res.errmsg ? res.errno + " - " + res.errmsg : (res.errmsg || res.errno)) + "。" : "刷新后再试试吧~"}`);
					} else {
						throw new Error("提示:<br/>获取下载链接失败,刷新网页后再试试吧~");
					}
				}

				batch.forEach(_item => {
					const item = res.list.find(li => li.fs_id == _item.fs_id);
					if (item) {
						Object.assign(_item, item);
						temp.glinks.push({ id: _item.fs_id, expires: (Date.now() + 4 * 60 * 60 * 1000), data: item });
					}
				});

View on GitHub (pinned to 417ea5e28a)

Solutions

  1. Refresh the Baidu Netdisk page to get a fresh page context/token, then retry.
  2. Re-run the script's authorization/token-acquisition flow so a new access_token is stored.
  3. If it recurs quickly, clear the script's stored Baidu value (the script manages `baidu_access_token`) and re-authorize.
  4. Check network/proxy time skew or caching that might replay an old token request.
Defensive patterns

Strategy: retry

Validate before calling

const token = base.getValue("baidu_access_token");
if (!token) { /* trigger re-authorization before calling the API */ }

Type guard

function isBaiduExpired(res) { return res && res.errno === 112; }

Try / catch

try {
  await fetchBaiduDownloadLinks(batch);
} catch (e) {
  if (String(e.message).includes("代码:112")) {
    // prompt user to refresh the Baidu page, then re-acquire token and retry once
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the Baidu download-link batch API while the `access_token`/page context bound to the request has expired — e.g. the access token was obtained long before the request, or the Baidu page state the token was issued against was invalidated server-side.

Common situations: Leaving a Baidu Netdisk tab open for hours then trying to fetch links; the token obtained in one session being reused after Baidu rotated it; server-side session invalidation (logout elsewhere, risk control).

Related errors


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