Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

347
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda