hmjz100/LinkSwift · error · Error

[阿里云盘] 获取文件 URL 失败

Error message

[阿里云盘] 获取文件 URL 失败

What it means

Fallback wrapper for Aliyun Drive's `this.getFilesUrl(selects, token)` rejection when the thrown value is not an Error instance. Resolving direct URLs calls Aliyun Drive's API with a Bearer token (`token_type access_token` from storage); API-side failures surface as this generic message unless an Error was already thrown.

Source

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

			}

			// 获取选择的文件列表
			let selects = this.getSelectedList();
			if (selects.length === 0) throw new Error("提示:<br/>请勾选要下载的文件哦~");
			if (selects.every(item => item.type !== "file")) throw new Error("提示:<br/>请打开文件夹后再勾选文件~");

			$doc.find(".loading-popup .loading-title").html(`链接获取中`);
			$doc.find(".loading-popup .swal2-html-container").html(`<div>正在获取文件对应的下载链接~</div>`);

			if (temp.page === "home") {
				selects = selects.filter(item => item.type === "file");
				const token = base.getStorage("token");
				if (!token || !token.token_type || !token.access_token) {
					return message.error("提示:<br/>请先登录网盘~");
				}
				selects = await this.getFilesUrl(selects, `${token.token_type} ${token.access_token}`).catch(e => {
					if (e instanceof Error) throw e;
					throw new Error(e?.message || e || "[阿里云盘] 获取文件 URL 失败");
				});
			} else {
				throw new Error("提示:<br/>页面错误~");
			}

			temp.links = [selects, {
				isFolder: v => v.type === "folder",
				getFileName: v => v.name,
				getFileSize: v => v.size,
				getFileLink: v => (v.downloadUrl || v.url),
				convert: {
					aria2: `--header "Referer:https://${location.host}/"`,
					curl: `-e "https://${location.host}/"`,
					bitcomet: `&refer=${encodeURIComponent(`https://${location.host}/`)}`
				},
				tooltip: config.$aliyun.dom
			}];
			base.showMainDialog(config.base.dom.button[temp.mode].title, base.generateDOM(temp.links), config.base.dom.button[temp.mode].footer);

View on GitHub (pinned to 417ea5e28a)

Solutions

  1. Re-obtain the token: log out/in to Aliyun Drive (or use the script's token-refresh) so storage holds a fresh access_token.
  2. Update the userscript to the latest version for current API endpoints.
  3. Retry after a cooldown if rate-limited (HTTP 429).
  4. Inspect DevTools Network for the failing request's status/body to identify the real error.
Defensive patterns

Strategy: try-catch

Validate before calling

const token = base.getStorage('token');
if (!token || !token.token_type || !token.access_token) { alert('请先登录网盘并刷新 token'); return; }

Type guard

function hasValidToken(t) { return !!(t && t.token_type && t.access_token); }

Try / catch

try { await getLinks(); } catch (e) { console.error('Aliyun link fetch failed:', e); if (await isTokenExpired()) { await refreshToken(); retry(); } }

Prevention

When it happens

Trigger: getFilesUrl's requests to Aliyun Drive's download-link API reject with a non-Error: expired/revoked access_token, 403/429 from Aliyun risk control, API path change, or network failure yielding a plain-string/object rejection.

Common situations: Aliyun Drive access tokens expire (they are short-lived) while stored in script storage; user re-logged in elsewhere invalidating the token; Aliyun tightened API rate limits; userscript outdated after an Aliyun API revision.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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