Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

342
Vistas
Node.js is not catching imap error, how to catch it?

I am creating an app that will auth user input. problem is that when the user input is wrong error is not caught and my app is crashing.

If i put

throw new Error("dasdas");

That error is caught but IMAP errors are not.

try {
  var imap = new Imap({
    user: email,
    password: password,
    host: "mail.metropolitan.ac.rs",
    port: 993,
    tls: true,
  });
  imap.connect();
  res.status(201).json({ success: true, person: email });
} catch (err) {
  console.log(err);
  return res.status(400).json({ success: false, msg: "data is wrong" });
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As shown in the documentation you need to register the error listener before connecting to the server like this as the error is emitted as an event and not thrown as a normal error would be

imap.once('error', function(err) {
  console.log(err);
});

(This needs to be done before connect()) you can read about this behaviour on this page

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda