Merge dependabot/npm_and_yarn/examples/typescript/smtp-client-pool/poolifier-2.6...
[poolifier.git] / src / pools / selection-strategies / worker-choice-strategy-context.ts
index 8c5a9587debbd4b66fba9a7630838fcc44cabc3c..7c7574fa7a39f55913282a60bd0becf35e88b6fc 100644 (file)
@@ -168,7 +168,7 @@ export class WorkerChoiceStrategyContext<
    * Executes the worker choice strategy in the context algorithm.
    *
    * @returns The key of the worker node.
-   * @throws {@link https://nodejs.org/api/errors.html#class-error} If the worker node key is null or undefined.
+   * @throws {@link https://nodejs.org/api/errors.html#class-error} If after configured retries the worker node key is null or undefined .
    */
   public execute (): number {
     const workerNodeKey = (
@@ -183,8 +183,11 @@ export class WorkerChoiceStrategyContext<
       this.choiceRetriesCount++
       return this.execute()
     } else if (workerNodeKey == null) {
-      throw new TypeError('Worker node key chosen is null or undefined')
+      throw new Error(
+        `Worker node key chosen is null or undefined after ${this.choiceRetriesCount} retries`
+      )
     }
+    this.choiceRetriesCount = 0
     return workerNodeKey
   }