{"record":{"id":"ddaf8905238187cc","repo":"pot-app/pot-desktop","slug":"get-userinfo-error-json-stringify-result","errorCode":null,"errorMessage":"Get UserInfo Error: ${JSON.stringify(result)}","messagePattern":"Get UserInfo Error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/window/Config/pages/Backup/utils/aliyun.jsx","lineNumber":158,"sourceCode":"export async function userInfo(token) {\n    const res = await fetch('https://openapi.alipan.com/oauth/users/info', {\n        headers: {\n            Authorization: `Bearer ${token}`,\n        },\n    });\n    if (res.ok) {\n        const result = res.data;\n        if (result.hasOwnProperty('avatar') && result.hasOwnProperty('name')) {\n            return { avatar: result['avatar'], name: result['name'] };\n        } else {\n            throw new Error(`Can not find avatar or name: ${JSON.stringify(result)}`);\n        }\n    } else {\n        const result = res.data;\n        if (result['message']) {\n            throw new Error(result['message']);\n        } else {\n            throw new Error(`Get UserInfo Error: ${JSON.stringify(result)}`);\n        }\n    }\n}\n\nexport async function accessToken(code) {\n    const res = await fetch('https://pot-app.com/api/ali_access_token', {\n        method: 'POST',\n        body: Body.json({\n            code,\n            refresh_token: '',\n        }),\n    });\n    if (res.ok) {\n        const result = res.data;\n        if (result['access_token']) {\n            return result['access_token'];\n        } else {\n            throw new Error(`Can not find access_token: ${JSON.stringify(result)}`);","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/pot-app/pot-desktop/blob/594d32ede96acd106b0256deaa8bb440ffcdff40/src/window/Config/pages/Backup/utils/aliyun.jsx#L140-L176","documentation":"Fallback error in userInfo(): the users/info request returned non-2xx and the error body had no `message` field, so the raw body is stringified into `Get UserInfo Error: <JSON>`. The token check failed at the HTTP level with an unrecognizable error payload.","triggerScenarios":"Calling userInfo(token) when openapi.alipan.com/oauth/users/info returns a non-2xx response whose res.data lacks `message` — e.g. 401 with an empty body, an HTML/WAF block page, or gateway error JSON.","commonSituations":"Completely invalid token format rejected before API error JSON is produced; network/proxy interception; Alipan service disruption; clock skew causing premature token rejection in some gateways.","solutions":["Inspect the stringified body and HTTP status to identify the responder.","Re-authenticate via qrcode()/accessToken() to get a fresh token.","Check network/proxy access to openapi.alipan.com.","Retry with backoff in case of a transient 5xx."],"exampleFix":"// before\nthrow new Error(`Get UserInfo Error: ${JSON.stringify(result)}`);\n// after\nif (res.status === 401) {\n    throw new Error('Token rejected (401) — re-authenticate via QR login');\n}\nthrow new Error(`Get UserInfo Error (HTTP ${res.status}): ${JSON.stringify(result)}`);","handlingStrategy":"try-catch","validationCode":"// preflight: token present and endpoint reachable\nconst reachable = await fetch('https://openapi.alipan.com/oauth/users/info', {\n  method: 'HEAD',\n}).then(r => r.status !== 0).catch(() => false);\nif (!reachable || !token) await reAuthenticate();","typeGuard":"function isUnauthorizedStatus(status) {\n  return status === 401 || status === 403;\n}","tryCatchPattern":"try {\n  const { avatar, name } = await userInfo(token);\n} catch (e) {\n  if (String(e.message).startsWith('Get UserInfo Error')) {\n    // opaque rejection — assume bad token, re-authenticate\n    token = await fullQrLoginFlow();\n    return userInfo(token);\n  }\n  throw e;\n}","preventionTips":["Treat any opaque users/info failure as an auth problem and re-authenticate once","Check network/proxy reachability before blaming the token","Log HTTP status with the stringified body for diagnosis","Retry at most once to avoid lockouts from repeated bad-token calls"],"tags":["network","oauth","access-token","alipan"],"backgroundTag":"api-error-response-missing-message","analyzedSha":"594d32ede96acd106b0256deaa8bb440ffcdff40","analyzedAt":"2026-09-02T18:12:21.811Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}