From 3164e1ea4ed331fc79473299f3b560368f254478 Mon Sep 17 00:00:00 2001 From: akirilyuk Date: Tue, 1 Feb 2022 14:54:47 +0100 Subject: [PATCH] add more error logs --- lib/tasks/cognigy/index.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/tasks/cognigy/index.js b/lib/tasks/cognigy/index.js index af02607a..c3385abf 100644 --- a/lib/tasks/cognigy/index.js +++ b/lib/tasks/cognigy/index.js @@ -68,17 +68,17 @@ class Cognigy extends Task { rejector = reject; }); this.taskQueue.push(async(cb) => { - this.logger.info("EXECUTING SAY TASK"); + this.logger.info('EXECUTING SAY TASK'); try { const result = await task(); resolver(result); cb(result); } catch (err) { - this.logger.error({err}, "could not execute task in task queue"); + this.logger.error({err}, 'could not execute task in task queue'); rejector(err); cb(err); } - this.logger.info("SAY TASK EXECUTED"); + this.logger.info('SAY TASK EXECUTED'); }); this.taskQueue.lastPromise = taskPromise; return taskPromise; @@ -154,8 +154,13 @@ class Cognigy extends Task { this.client.removeAllListeners(); if (this.client && this.client.connected) this.client.disconnect(); - // end the task queue AFTER we have removed all listeneres since now we cannot get new stuff inside the queue - this.taskQueue.end(); + try { + // end the task queue AFTER we have removed all listeneres since now we cannot get new stuff inside the queue + this.taskQueue.end(); + } catch (err) { + this.logger.error({err}, 'could not end tasks queue!!'); + } + if (!this.hasReportedFinalAction) { this.reportedFinalAction = true; @@ -229,7 +234,7 @@ class Cognigy extends Task { async _onBotFinalPing(cs, ep) { this.logger.info({prompts: this.prompts}, 'Cognigy:_onBotFinalPing'); await this.taskQueue.lastPromise; - this.gatherTask = this._makeGatherTask({textPrompt: "this should be changed"}); + this.gatherTask = this._makeGatherTask({textPrompt: 'this should be changed'}); this.gatherTask.exec(cs, ep, this) .catch((err) => this.logger.info({err}, 'Cognigy gather task returned error')); this.prompts = []; @@ -256,11 +261,11 @@ class Cognigy extends Task { const text = parseBotText(evt); if (evt.data) this.config.update(evt.data); if (text) { - + await this._enqueueTask((async() => { - this.logger.info({text}, "received text"); - const sayTask = this._makeSayTask(text); - await sayTask.exec(cs, ep, this); + this.logger.info({text}, 'received text'); + const sayTask = this._makeSayTask(text); + await sayTask.exec(cs, ep, this); }).bind(this)); }