{"record":{"id":"6845baecacbf26d5","repo":"yikart/AiToEarn","slug":"google-login-failed-error-message","errorCode":null,"errorMessage":"Google login failed: ${error.message}","messagePattern":"Google login failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"project/aitoearn-electron/server/src/modules/plat/google/google.service.ts","lineNumber":511,"sourceCode":"\n      // const expires = 30 * 24 * 60 * 60\n      // console.log(\"accessTokenInfo:---\", accessTokenInfo);\n      // console.log(\"expires:---\", accessTokenInfo.expires_in);\n      // this.redisService.setKey(\n      //   `google:accessToken:${userId}`,\n      //   accessTokenInfo,\n      //   accessTokenInfo.expires_in\n      // );\n      const loginResult = {\n        token: null,\n        type: \"login\",\n        userInfo: TokenInfo\n      }\n      loginResult.token = systemToken\n      return loginResult;\n    } catch (error) {\n      console.error('Google login error:', error);\n      throw new Error(`Google login failed: ${error.message}`);\n    }\n  }\n\n  async setUserAccessToken_V2(data: {\n    code: string;\n    state: string;\n  }) {\n\n    const { code, state } = data;\n    console.log(\"================ code state=======================\")\n    console.log(code, state);\n    console.log(\"=============================================\")\n\n    try {\n      const params = new URLSearchParams({\n        code: code,\n        redirect_uri: `${this.webRenderBaseUrl}/api/plat/google/auth/accessToken`,\n        client_id: this.webClientId,","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-electron/server/src/modules/plat/google/google.service.ts#L493-L529","documentation":"googleLogin wraps its entire body in try/catch; on any failure (token verification, user lookup, account linking, token issuance) it logs and rethrows as Error(`Google login failed: ${error.message}`). The original cause is preserved only in the message string, so the underlying error (e.g. 'Invalid Google token', DB failure, network error) is flattened.","triggerScenarios":"Any exception thrown inside googleLogin — including verifyIdToken failures (expired/invalid token, audience mismatch), database errors when creating/linking the Google account, or downstream token generation — is rethrown with this message.","commonSituations":"Expired or tampered ID token; token issued for a different clientId; MongoDB/DB unique constraint when linking an already-linked Google account; network failure calling Google tokeninfo; bugs in subsequent token minting.","solutions":["Read the inner error.message in the thrown string to identify the root cause (it is appended)","Log the full error stack, not just message, before rethrowing","Preserve the original error via { cause: error } so instanceof checks and stacks survive","Handle known causes specifically (invalid token -> 401, DB conflict -> 409) instead of one generic message","In the client, surface the inner message to guide the user (e.g. re-authenticate)"],"exampleFix":"// before\n} catch (error) {\n  console.error('Google login error:', error);\n  throw new Error(`Google login failed: ${error.message}`);\n}\n// after\n} catch (error) {\n  console.error('Google login error:', error);\n  throw new Error(`Google login failed: ${error.message}`, { cause: error });\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await googleService.googleLogin(idToken, clientId);\n} catch (err) {\n  const cause = err?.cause?.message || err.message;\n  logger.error('Google login failed', cause);\n  if (cause.includes('Invalid Google token')) return res.status(401).end();\n  return res.status(502).json({ error: 'Google login unavailable' });\n}","preventionTips":["Preserve original errors with { cause: error } when wrapping","Log full stack traces, not only error.message","Map known inner causes to distinct HTTP statuses (401 vs 409 vs 502)","Monitor the inner message to detect token vs infra failures"],"tags":["google","oauth","login","error-wrapping"],"backgroundTag":"google-login-failed","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}