{"record":{"id":"e2d21398ced17730","repo":"hmjz100/LinkSwift","slug":"br-res-error-description-res-er","errorCode":null,"errorMessage":"错误：<br/>令牌刷新失败，${res?.error_description || res?.error || \"未知错误\"}","messagePattern":"错误：<br/>令牌刷新失败，(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":7716,"sourceCode":"\t\t\t\t\tconst res = await base.post(config.$xunlei.api.getCaptchaToken, {\r\n\t\t\t\t\t\tclient_id: clientId,\r\n\t\t\t\t\t\taction: \"get:/drive/v1/about\",\r\n\t\t\t\t\t\tdevice_id: deviceId,\r\n\t\t\t\t\t\tmeta: {\r\n\t\t\t\t\t\t\tusername: \"\", phone_number: \"\", email: \"\",\r\n\t\t\t\t\t\t\tpackage_name: location.host,\r\n\t\t\t\t\t\t\tclient_version: clientVersion,\r\n\t\t\t\t\t\t\tcaptcha_sign: this._getCaptchaSign(clientId, clientVersion, location.host, deviceId, timestamp.toString()),\r\n\t\t\t\t\t\t\ttimestamp: timestamp.toString(),\r\n\t\t\t\t\t\t\tuser_id: userId\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}, { \"Content-Type\": \"application/json\" });\r\n\r\n\t\t\t\t\tif (res?.captcha_token) {\r\n\t\t\t\t\t\tcap = { token: res.captcha_token, expires_at: new Date(timestamp + res.expires_in * 1000).toString() };\r\n\t\t\t\t\t\tbase.setStorage(capKey, cap);\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tthrow new Error(`错误：<br/>令牌刷新失败，${res?.error_description || res?.error || \"未知错误\"}`);\r\n\t\t\t\t\t}\r\n\t\t\t\t} else if (!creds || !cap || !clientId || !deviceId) {\r\n\t\t\t\t\tthrow new Error(`错误：<br/>请先登录网盘后再获取文件呢~`);\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn { credentials: creds, captcha: cap, device_id: deviceId };\r\n\t\t\t});\r\n\t\t},\r\n\t\tasync getFileUrl(item, index, isRetry = false) {\r\n\t\t\tif (item.downloadUrl) return { index, downloadUrl: item.downloadUrl };\r\n\r\n\t\t\t// 获取当前内存中的 token\r\n\t\t\tconst token = await this.getToken(false, false).catch(e => {\r\n\t\t\t\tif (e instanceof Error) throw e;\r\n\t\t\t\tthrow new Error(e?.message || e || \"[迅雷云盘] 获取令牌失败\");\r\n\t\t\t});\r\n\r\n\t\t\tconst res = await base.get(config.$xunlei.api.getLink + item.id, {\r","sourceCodeStart":7698,"sourceCodeEnd":7734,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L7698-L7734","documentation":"Thrown during credential/captcha token refresh when the refresh API responds successfully at the HTTP layer but does NOT return a captcha_token. The code expects res.captcha_token plus expires_in to cache a captcha token; if the response lacks it, it surfaces the server's error_description / error fields, falling back to '未知错误'. It indicates the cloud provider refused the token refresh.","triggerScenarios":"Calling the token-refresh endpoint (POST with JSON body) and receiving a JSON body without captcha_token — e.g. {error: 'invalid_grant'} or {error_description: '...'} — typically when stored credentials (creds) are expired, revoked, or the device/client ID is rejected.","commonSituations":"User logged out or changed password on the cloud drive, invalidating stored refresh credentials; captcha/anti-bot policy change server-side; clock skew making cached captcha look valid; clientId/deviceId mismatch after clearing browser storage.","solutions":["Log out and log back into the cloud drive in the userscript to regenerate credentials","Read the embedded error_description in the message (e.g. invalid_grant) and act on it — most often re-authentication","Clear the userscript's cached storage keys (credentials, captcha) and retry the refresh","Check system clock accuracy if the error mentions expired/invalid token timestamps"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const creds = base.getStorage(credsKey);\nif (!creds?.refresh_token) { promptLogin(); }","typeGuard":"function hasCaptcha(res) { return typeof res?.captcha_token === 'string' && res.captcha_token.length > 0; }","tryCatchPattern":"try { await refreshCreds(); } catch (e) { if (e.message.includes('令牌刷新失败')) { clearStoredCredentials(); promptLogin(); } else throw e; }","preventionTips":["Re-authenticate when password changes elsewhere","Keep system clock accurate","Clear cached captcha on repeated refresh failures","Surface error_description to the user"],"tags":["authentication","token-refresh","oauth","cloud-drive"],"backgroundTag":"token-refresh-failed","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}