{"record":{"id":"2334a3b7f14bbd08","repo":"yikart/AiToEarn","slug":"responsecode-accountnotfound-2334a3","errorCode":"ResponseCode.AccountNotFound","errorMessage":"AccountNotFound","messagePattern":"AccountNotFound","errorType":"error_code","errorClass":"AppException","httpStatus":null,"severity":"error","filePath":"project/aitoearn-backend/apps/aitoearn-server/src/core/channels/auth/auth.service.ts","lineNumber":479,"sourceCode":"  }\n\n  async markSessionFailed(sessionId: string, errorCode: number): Promise<void> {\n    const session = await this.redis.getChannelAuthSession<AuthSession>(sessionId)\n    if (!this.isAccountAuthSessionRecord(session) || this.isSessionExpired(session) || session.status !== ChannelAuthSessionStatus.Pending) {\n      return\n    }\n\n    session.status = ChannelAuthSessionStatus.Failed\n    session.errorCode = errorCode\n    delete session.rootCredentialId\n    delete session.selectableAccounts\n    await this.redis.saveChannelAuthSession(session.id, session)\n  }\n\n  async getAccountAuthStatus(userId: string, platform: AccountType, accountId: string) {\n    const account = await this.accountRepo.getByIdAndUserId(accountId, userId)\n    if (!account) {\n      throw new AppException(ResponseCode.AccountNotFound)\n    }\n    if (account.type !== platform) {\n      throw new AppException(ResponseCode.ChannelAuthPlatformMismatch)\n    }\n\n    return { status: account.status }\n  }\n\n  async revokeCredential(accountId: string, userId: string): Promise<void> {\n    const account = await this.getCredentialAccount(accountId, userId)\n    const credential = await this.credentialService.getCredential(accountId)\n\n    if (credential) {\n      const provider = this.registry.getAuth(account.type)\n      await provider.revoke?.({\n        accessToken: credential.accessToken,\n        refreshToken: credential.refreshToken,\n        platformUid: account.uid,","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/apps/aitoearn-server/src/core/channels/auth/auth.service.ts#L461-L497","documentation":"getAccountAuthStatus looks up the account by (accountId, userId); if none is found, AccountNotFound is thrown. This means the account does not exist for that user — a wrong id or wrong-user access produces the same result.","triggerScenarios":"Querying auth status with an accountId belonging to another user, a deleted/revoked account, or a malformed/nonexistent id.","commonSituations":"Client cache holding account ids after the account was disconnected; switching environments (China vs international) where the id does not exist; typos or truncated ids in scripts.","solutions":["Verify the accountId exists for the authenticated user (list accounts first)","Re-fetch the account list to refresh stale client caches","Check you are hitting the correct environment (aitoearn.cn vs aitoearn.ai) for that id"],"exampleFix":"// before\nconst status = await api.getAccountAuthStatus(userId, platform, cachedAccountId)\n// after\nconst accounts = await api.listAccounts(userId)\nconst acct = accounts.find(a => a.id === cachedAccountId)\nif (!acct) { await refreshAccounts(); return }\nconst status = await api.getAccountAuthStatus(userId, platform, acct.id)","handlingStrategy":"validation","validationCode":"const accounts = await api.listAccounts(userId)\nconst exists = accounts.some(a => a.id === accountId)\nif (!exists) throw new Error(`Account ${accountId} not found for user`)","typeGuard":"function accountExists(a): a is Account { return typeof a?.id === 'string' && a.userId === currentUserId }","tryCatchPattern":"try {\n  return await api.getAccountAuthStatus(userId, platform, accountId)\n} catch (e) {\n  if (e.code === 'AccountNotFound') {\n    await syncAccounts(); return null // treat as disconnected\n  }\n  throw e\n}","preventionTips":["Refresh account caches after disconnect/revoke operations","Verify environment/key pairing (cn vs ai) before using stored ids","Validate ids come from server responses, not user input"],"tags":["account-not-found","channel-auth","rest"],"backgroundTag":"account-not-found","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}