Foundry376/Mailspring · error

O365 profile request failed: ${me.error.code}: ${me.error.me

Error message

O365 profile request failed: ${me.error.code}: ${me.error.message}

What it means

Guard in buildMicrosoftAccountFromAuthResponse handling Microsoft Graph's quirk of returning HTTP 200 with an error object in the body: the me payload contains an error property, so the profile is treated as failed even though the status was ok. The thrown message surfaces the Graph error code and message.

Source

Thrown at app/internal_packages/onboarding/lib/onboarding-helpers.ts:300

      code_verifier: CODE_VERIFIER,
      grant_type: `authorization_code`,
      redirect_uri: `http://localhost:${LOCAL_SERVER_PORT}/desktop`,
    }
  );

  // get the user's email address
  const meResp = await fetch('https://graph.microsoft.com/v1.0/me', {
    headers: { Authorization: `Bearer ${access_token}` },
  });
  const me = await meResp.json();
  if (!meResp.ok) {
    throw new Error(
      `O365 profile request returned ${meResp.status} ${meResp.statusText}: ${JSON.stringify(me)}`
    );
  }
  // The Graph API can return 200 OK with an error body in some edge cases
  if (me.error) {
    throw new Error(`O365 profile request failed: ${me.error.code}: ${me.error.message}`);
  }

  // Try multiple sources to find the email address. For most work accounts `mail` or
  // `userPrincipalName` is set. For personal MSA accounts or accounts without Exchange
  // Online licenses, fall back to the id_token claims (requires openid+email scopes).
  let emailAddress: string | null = me.mail || me.userPrincipalName || null;

  if (!emailAddress && id_token) {
    try {
      // Decode id_token JWT payload (base64url encoded) to extract email claims
      const payload = JSON.parse(Buffer.from(id_token.split('.')[1], 'base64').toString('utf8'));
      const candidate: string = payload.email || payload.preferred_username || payload.unique_name;
      // Only accept values that look like real email addresses (not GUID-based UPNs)
      if (candidate && /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(candidate)) {
        emailAddress = candidate;
      }
    } catch {
      // ignore token parsing errors

View on GitHub (pinned to 648c685d60)

Solutions

  1. Retry onboarding — transient Graph errors (throttling, temporary auth propagation) often resolve
  2. Verify scopes and token audience based on the embedded error code
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at app/internal_packages/onboarding/lib/onboarding-helpers.ts:300 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Foundry376/Mailspring@648c685d60 (2026-09-03). Data as JSON: /api/errors/be62deb74534cf54. Report an issue: GitHub.