In my NodeJS server, run by PM2, I authenticate my users with a LAPD service using npm module "ldap-authentication".
const { authenticate } = require('ldap-authentication');
...
try {
const auth = await authenticate(options);
return auth;
} catch(err){
return err;
}
It works fine when credentials are Ok.
When credentials are wrong function throws a proper error that can be caught and easily handled.
The problem comes when there is no connection and the "getaddrinfo ENOTFOUND" error arises,
Error: getaddrinfo ENOTFOUND xxx.xxx.corp
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
as the code crashes without catching any error causing an inadmissible problem (despite PM2 restarts the code). I need to handle a possible broken connection and avoid the server crash.
It looks like is not the problem about catching errors from an async function as other types of errors for this function are caught. Attending to this link seems it is a problem with this particular error in this particular module.
Any ideas?