1

I have a primary ldap server url, say urlA and multiple backup server urls in a list. If the connection couldn't be made to the primary ldap server, the backup servers will be tried in the order they appear in the list. I am using ldapjs createClient function to create a client. ldapjs.createClient({ url: urlA })

How do I handle a connection error and retry on backup server in order till I connect to one of them?

  • Welcome to Stack Overflow! Stack Overflow is for programming questions, not questions about using or configuring Unix and its utilities. Suggest Super User would be better places for questions like this. – pradosh nair Nov 18 '19 at 18:21

1 Answers1

0

I know I'm late to this, but thought I'd answer in case someone came across this from a search.

I'm using ldapts, which is based on ldapjs and have done the same thing with the ts version.

This can be accomplished by wrapping your createClient code in a try...catch and either a loop structure of some sort or a recursive promise.then.catch structure (which might be desirable if you're doing async calls).

It would be best to put the try...catch inside the loop. That should keep the code from kicking out of the loop on the first error.

For an example of a recursive promise.then.catch implementation, see this article.