Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
Express-validator returning empty array of erros even when there are errors

I am trying to validate user input with express validator and I get an empty array of errors which is incorrect because I sent the wrong input to test. When I console.log(errors), I get this : Result { formatter: [Function: formatter], errors: [] }

login = async (req, res) => {
  try {
    body("email").isEmail(), body("password").isLength({ min: 5 });
    const errors = validationResult(req);
    console.log(errors);
    if (!errors.isEmpty()) {
      return res.status(400).json({ errors: errors.array() });
    }
    const user = await User.findOne({ where: { email: req.body.email } });
    if (!user) {
      return res
        .status(400)
        .json({ error_msg: "An account for this email does not exist" });
    }
    const validPass = await bcrypt.compare(req.body.password, user.password);
    if (!validPass) {
      return res.status(400).json({ error_msg: "E-mail or password is wrong" });
    }
    const token = await getSignedToken(user);
    return res.status(200).json({ token: token });
  } catch (error) {
    return res.status(400).json({ error_msg: error.message });
  }
};

This is my sample input: { "email":"samadejoro", "password":"sams" }

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!