Not getting standard LDAP Error codes in Error object in ldapjs
Hi Team,
We are connecting to Microsoft Active Directory using ldapjs. Whenever we are trying to add object that is already available we are getting below error.
{ EntryAlreadyExistsError: 00002071: UpdErr: DSID-0305038D, problem 6005 (ENTRY_EXISTS), data 0 at messageCallback (D:\ImplementationCheck\node_modules\ldapjs\lib\client\client.js:1421:45)
at Parser.onMessage (D:\ImplementationCheck\node_modules\ldapjs\lib\client\client.js:1091:14)
at Parser.emit (events.js:198:13)
at Parser.write (D:\ImplementationCheck\node_modules\ldapjs\lib\messages\parser.js:111:8)
at TLSSocket.onData (D:\ImplementationCheck\node_modules\ldapjs\lib\client\client.js:1078:22)
at TLSSocket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at TLSSocket.Readable.push (_stream_readable.js:224:10)
at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
lde_message:
'00002071: UpdErr: DSID-0305038D, problem 6005 (ENTRY_EXISTS), data 0\n\u0000',
lde_dn: null }
Here we are expecting LDAP Standard Error Code <68> so what are the changes required to have standard LDAP error code in error object along with server error.
Please find the code snippet below.
var ldap = require("ldapjs");
var fs = require("fs");
const assert = require("assert");
var opts = {
ca: [fs.readFileSync("./ldaps.cer")],
rejectUnauthorized: true
};
var client = ldap.createClient({
url: 'ldaps://mytestinstance:636',
tlsOptions: opts,
reconnect: true
});
client.on('error', function(err) {
console.warn('LDAP connection failed : ', err);
});
client.bind("CN=admin,DC=mytest,DC=com", "adminpassword", function (err) {
console.log('In bind method');
assert.ifError(err);
});
var newDN = "cn=testComputer,ou=testou,DC=mytest,DC=com";
var newUser = {
cn: 'testComputer',
objectClass: 'computer',
description: 'This is test implementation hence this is test description.'
}
client.add(newDN, newUser,function(err, resp) {
console.log('newDN : ', newDN);
console.log('newUser : ' ,newUser);
if(err){
console.log('error',err);//The error above mentioned is from here
}else{
console.log('new user is success', JSON.stringify(resp));
}
})
What you are showing is that you have an instance of EntryAlreadyExistsError. That means you should be able to console.log(err.code) and see 68. Is this not the case?
Hi @jsumners
We could not capture error code using err.code. As per our analysis nodejs is not returning error code 68 in the error details.
Thank you.
Redacted trace logs would be very helpful.
👋
On February 22, 2023, we released version 3 of this library. As a result, we are closing this issue/pull request.
Please see issue #839 for more information, including how to proceed if you feel this closure is in error.