pot-app/pot-desktop · error · Error

Can not find access_token

Error message

Can not find access_token: ${JSON.stringify(result)}

What it means

The accessToken() helper exchanges the OAuth auth code via https://pot-app.com/api/ali_access_token and expects `access_token` in a 200 response. If it's missing, it throws `Can not find access_token: <body JSON>` — the exchange endpoint returned 200 but not the token payload.

Solutions

  1. Inspect the JSON dump for an embedded error describing why the exchange failed.
  2. Restart the whole QR login flow to get a fresh authCode — codes are single-use and short-lived.
  3. Exchange the code immediately after scanning; do not cache or retry with the same code.
  4. Verify the pot-app.com relay API is up and still returns `access_token` (consider using Alipan's token endpoint directly if it changed).

Example fix

// before
if (result['access_token']) {
    return result['access_token'];
} else {
    throw new Error(`Can not find access_token: ${JSON.stringify(result)}`);
}
// after
if (result && typeof result.access_token === 'string') {
    return result.access_token;
}
console.error('token exchange failed', result);
throw new Error('Auth code invalid or already used — restart QR login to get a new code');
Defensive patterns

Strategy: validation

Validate before calling

// validate the auth code shape before exchanging, and exchange immediately after scan
function looksLikeAuthCode(code) {
  return typeof code === 'string' && code.length > 10;
}
if (!looksLikeAuthCode(code)) throw new Error('Invalid authCode — restart QR login');

Type guard

function hasAccessToken(r) {
  return r && typeof r === 'object' && typeof r.access_token === 'string' && r.access_token.length > 0;
}

Try / catch

try {
  const token = await accessToken(code);
} catch (e) {
  if (String(e.message).startsWith('Can not find access_token')) {
    // code single-use/expired — never retry same code
    const { url, sid: newSid } = await qrcode();
    promptUserToRescan(url, newSid);
  } else {
    showError(e.message);
  }
}

Prevention

When it happens

Trigger: Calling accessToken(code) with an HTTP 200 whose res.data lacks `access_token` — e.g. the auth code was already redeemed/expired and the pot-app backend returned a JSON error object with 200, or its response schema changed.

Common situations: Reusing an authCode that Alipan allows only once (single-use codes); the code expired between the QR scan and the exchange; the pot-app relay API changing shape or being down while still returning 200 with an error body.

Related errors


AI-assisted analysis of pot-app/pot-desktop@594d32ede9 (2026-09-02). Data as JSON: /api/errors/6590a91976f6321e. Report an issue: GitHub.

Appendix: source

Thrown at src/window/Config/pages/Backup/utils/aliyun.jsx:176

            throw new Error(`Get UserInfo Error: ${JSON.stringify(result)}`);
        }
    }
}

export async function accessToken(code) {
    const res = await fetch('https://pot-app.com/api/ali_access_token', {
        method: 'POST',
        body: Body.json({
            code,
            refresh_token: '',
        }),
    });
    if (res.ok) {
        const result = res.data;
        if (result['access_token']) {
            return result['access_token'];
        } else {
            throw new Error(`Can not find access_token: ${JSON.stringify(result)}`);
        }
    } else {
        const result = res.data;
        if (result['message']) {
            throw new Error(result['message']);
        } else {
            throw new Error(`Get accessToken Error: ${JSON.stringify(result)}`);
        }
    }
}

async function driveId(token) {
    const res = await fetch('https://openapi.alipan.com/adrive/v1.0/user/getDriveInfo', {
        method: 'POST',
        headers: {
            Authorization: `Bearer ${token}`,
        },
    });

View on GitHub (pinned to 594d32ede9)