{"record":{"id":"e307256fbdca8a25","repo":"Foundry376/Mailspring","slug":"gmail-profile-request-returned-meresp-status","errorCode":null,"errorMessage":"Gmail profile request returned ${meResp.status} ${meResp.statusText}: ${JSON.stringify(me)}","messagePattern":"Gmail profile request returned (.+?) (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/internal_packages/onboarding/lib/onboarding-helpers.ts","lineNumber":234,"sourceCode":"  /// Exchange code for an access token\n  const { access_token, refresh_token } = await fetchPostWithFormBody<TokenResponse>(\n    'https://www.googleapis.com/oauth2/v4/token',\n    {\n      code: code,\n      client_id: GMAIL_CLIENT_ID,\n      client_secret: GMAIL_CLIENT_SECRET,\n      redirect_uri: `http://127.0.0.1:${LOCAL_SERVER_PORT}`,\n      grant_type: 'authorization_code',\n    }\n  );\n\n  // get the user's email address\n  const meResp = await fetch('https://www.googleapis.com/oauth2/v1/userinfo?alt=json', {\n    headers: { Authorization: `Bearer ${access_token}` },\n  });\n  const me = await meResp.json();\n  if (!meResp.ok) {\n    throw new Error(\n      `Gmail profile request returned ${meResp.status} ${meResp.statusText}: ${JSON.stringify(me)}`\n    );\n  }\n  const account = await expandAccountWithCommonSettings(\n    new Account({\n      name: me.name,\n      emailAddress: me.email,\n      provider: 'gmail',\n      settings: {\n        refresh_client_id: GMAIL_CLIENT_ID,\n        refresh_token: refresh_token,\n      },\n    })\n  );\n\n  account.id = idForAccount(me.email, account.settings);\n\n  // test the account locally to ensure the All Mail folder is enabled","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/Foundry376/Mailspring/blob/648c685d602ece6bb00c22534b8734de6ac644b3/app/internal_packages/onboarding/lib/onboarding-helpers.ts#L216-L252","documentation":"Guard in buildGmailAccountFromAuthResponse: after successfully exchanging the OAuth code for tokens, the request to Google's userinfo endpoint returned a non-ok status. The access token was obtained but the account's email address could not be resolved, so account creation aborts; commonly an invalid/expired token or scope (email scope missing).","triggerScenarios":"Thrown at app/internal_packages/onboarding/lib/onboarding-helpers.ts:234 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the requested OAuth scopes include the userinfo/email scope","Retry the flow to get a fresh access token if it expired","Log the embedded response body to identify the Google error code"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"648c685d602ece6bb00c22534b8734de6ac644b3","analyzedAt":"2026-09-03T02:00:24.311Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}