{"record":{"id":"82fb90a24f0383b5","repo":"YMFE/yapi","slug":"third-login-e-message","errorCode":null,"errorMessage":"third_login: ${e.message}","messagePattern":"third_login: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/controllers/user.js","lineNumber":207,"sourceCode":"          passsalt: passsalt,\n          role: 'member',\n          add_time: yapi.commons.time(),\n          up_time: yapi.commons.time(),\n          type: 'third'\n        };\n        user = await userInst.save(data);\n        await this.handlePrivateGroup(user._id, username, email);\n        yapi.commons.sendMail({\n          to: email,\n          contents: `<h3>亲爱的用户：</h3><p>您好，感谢使用YApi平台，你的邮箱账号是：${email}</p>`\n        });\n      }\n\n      this.setLoginCookie(user._id, user.passsalt);\n      return true;\n    } catch (e) {\n      console.error('third_login:', e.message); // eslint-disable-line\n      throw new Error(`third_login: ${e.message}`);\n    }\n  }\n\n  /**\n   * 修改用户密码\n   * @interface /user/change_password\n   * @method POST\n   * @category user\n   * @param {Number} uid 用户ID\n   * @param {Number} [old_password] 旧密码, 非admin用户必须传\n   * @param {Number} password 新密码\n   * @return {Object}\n   * @example ./api/user/change_password.json\n   */\n  async changePassword(ctx) {\n    let params = ctx.request.body;\n    let userInst = yapi.getInst(userModel);\n","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/YMFE/yapi/blob/59bade3a8a43e7db077d38a4b0c7c584f30ddf8c/server/controllers/user.js#L189-L225","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the original message after the 'third_login: ' prefix and fix the underlying cause (LDAP config, network, DB).","Verify third-party login plugin config (connection URL, bind credentials, base DN) in config.json.","Test connectivity from the server to the auth provider (curl/ldapsearch).","Check server logs — console.error('third_login:', e.message) logged the same message before rethrow."],"exampleFix":"// before: generic failure\nthrow new Error(`third_login: ${e.message}`);\n// after: log full context for diagnosis\nconsole.error('third_login failed:', e);\nthrow new Error(`third_login: ${e.message}`);","handlingStrategy":"try-catch","validationCode":"if (!ldapConfig || !ldapConfig.server) throw new Error('third-party login not configured');","typeGuard":null,"tryCatchPattern":"try {\n  await handleThirdLogin(req, res);\n} catch (e) {\n  if (String(e.message).startsWith('third_login:')) {\n    console.error('third-party login failed:', e.message);\n    // return 401/500 with sanitized message\n  } else { throw e; }\n}","preventionTips":["Validate third-party login config in config.json at startup.","Monitor auth provider health/connectivity before login attempts.","Keep the original error message when wrapping (the prefix pattern preserves it)."],"tags":["authentication","third-party-login","error-wrapping"],"backgroundTag":"third-party-auth-failed","analyzedSha":"59bade3a8a43e7db077d38a4b0c7c584f30ddf8c","analyzedAt":"2026-08-29T08:45:22.203Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}