YMFE/yapi · error

third_login: ${e.message}

Error message

third_login: ${e.message}

What it means

handleThirdLogin wraps its whole third-party login flow in try/catch and rethrows any failure (LDAP/OAuth lookup, DB errors, cookie setting) prefixed with 'third_login: '. It means the external auth or downstream step failed, not the credentials themselves necessarily — the original message is preserved after the prefix.

Source

Thrown at server/controllers/user.js:207

          passsalt: passsalt,
          role: 'member',
          add_time: yapi.commons.time(),
          up_time: yapi.commons.time(),
          type: 'third'
        };
        user = await userInst.save(data);
        await this.handlePrivateGroup(user._id, username, email);
        yapi.commons.sendMail({
          to: email,
          contents: `<h3>亲爱的用户:</h3><p>您好,感谢使用YApi平台,你的邮箱账号是:${email}</p>`
        });
      }

      this.setLoginCookie(user._id, user.passsalt);
      return true;
    } catch (e) {
      console.error('third_login:', e.message); // eslint-disable-line
      throw new Error(`third_login: ${e.message}`);
    }
  }

  /**
   * 修改用户密码
   * @interface /user/change_password
   * @method POST
   * @category user
   * @param {Number} uid 用户ID
   * @param {Number} [old_password] 旧密码, 非admin用户必须传
   * @param {Number} password 新密码
   * @return {Object}
   * @example ./api/user/change_password.json
   */
  async changePassword(ctx) {
    let params = ctx.request.body;
    let userInst = yapi.getInst(userModel);

View on GitHub (pinned to 59bade3a8a)

Solutions

  1. Read the original message after the 'third_login: ' prefix and fix the underlying cause (LDAP config, network, DB).
  2. Verify third-party login plugin config (connection URL, bind credentials, base DN) in config.json.
  3. Test connectivity from the server to the auth provider (curl/ldapsearch).
  4. Check server logs — console.error('third_login:', e.message) logged the same message before rethrow.

Example fix

// before: generic failure
throw new Error(`third_login: ${e.message}`);
// after: log full context for diagnosis
console.error('third_login failed:', e);
throw new Error(`third_login: ${e.message}`);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!ldapConfig || !ldapConfig.server) throw new Error('third-party login not configured');

Try / catch

try {
  await handleThirdLogin(req, res);
} catch (e) {
  if (String(e.message).startsWith('third_login:')) {
    console.error('third-party login failed:', e.message);
    // return 401/500 with sanitized message
  } else { throw e; }
}

Prevention

When it happens

Trigger: Any exception inside handleThirdLogin: the third-party auth provider (e.g. LDAP) call throws, user record creation/lookup fails, setLoginCookie throws, or this.setLoginCookie path errors. Called from the login controller when a third-party login method is used.

Common situations: LDAP server unreachable or misconfigured in config.json, network timeouts to the identity provider, DB write failures while creating the user on first third-party login, email/username field mapping mismatches.


AI-assisted analysis of YMFE/yapi@59bade3a8a (2026-08-29). Data as JSON: /api/errors/82fb90a24f0383b5. Report an issue: GitHub.