'Connection failure error unable to handle in passport-windowsauth, how to handle it

I'm trying to connect ldaps server using passport-windowsauth. If I provide valid credential the connection is working fine. If the credential is not valid then connection throwing an error something below

LDAP connection error: LDAPError [InvalidCredentialsError]: 80090308: LdapErr: DSID-0C090447, comment: AcceptSecurityContext error, data 52e, v3839

it throw an error I'm not able to handle it. I'm not getting in error response of middleware

function createStrategy(req) {
  let strategy = new WindowsStrategy(
    {
      ldap: {
        url: "ldap://corp.company.com:389/DC=corp,DC=company,DC=com",
        base: "DC=corp,DC=company,DC=com",
        bindDN: `${req.body.username}@corp.company.com`,
        bindCredentials: `${req.body.password}`,
        tlsOptions: {
          ca: [fs.readFileSync("./chain.pem")],
          rejectUnauthorized: true,
        },
      },
      integrated: false,
    },
    function (profile, done) {
      if (!profile) {
        return done(null, false, { message: "Invalid Username or password" });
      } else {
        return done(null, profile);
      }
    }
  );
  return strategy;
}

function login(req, res, next) {
  var strategy = createStrategy(req);
  passport.authenticate(
    strategy,
    {
      handleErrorsAsFailures: true,
      failureErrorCallback: true,
      badRequestMessage: true,
      invalidCredentials: true,
      noSuchObject: true,
      userNotFound: true,
      constraintViolation: true,
    },
    function (err, user) {
      if (err) {
        return next(err);
      }
      if (!user) {
        return res.send({ success: false, message: "signupfailed" });
      }
      return res.json({
        success: true,
        message: "signup succeeded",
        user: user,
      });
    }
  )(req, res, next);
}

app.get("/login", (req, res) => {
  res.sendFile(__dirname + "/index.html");
});

app.post("/login", login, (err, req, res, next) => {
  if (err) {
    return res.status(401).send("you have done a bad login");
  }
  next(err);
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source