From 58b79b40edfdd39ab02e636388de15037eb0a48d Mon Sep 17 00:00:00 2001 From: Tim Haley Date: Wed, 27 Jul 2022 15:54:44 -0400 Subject: [PATCH 1/2] Ensure callback is called when envoking errorHanlder A property, errorHanlder, was recently added which will be called instead of throwing an error in the .flush() method. This is important because errors in .flush() could, previously, only be handled via process.on('uncaughtException', err => { ... }). However, this property is currently unusable as, when the flush method invokes this property, it fails to call the callbacks of the events being flushed. This commit makes sure the callbacks are called. --- index.js | 1 + test.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/index.js b/index.js index 60c8bc18..66a8427f 100644 --- a/index.js +++ b/index.js @@ -298,6 +298,7 @@ class Analytics { }) .catch(err => { if (typeof this.errorHandler === 'function') { + done(err) return this.errorHandler(err) } diff --git a/test.js b/test.js index 34766e22..9dd33ce4 100644 --- a/test.js +++ b/test.js @@ -381,6 +381,23 @@ test('flush - do not throw on axios failure if errorHandler option is specified' t.true(errorHandler.calledOnce) }) +test('flush - evoke callback when errorHandler option is specified', async t => { + const errorHandler = spy() + const client = createClient({ errorHandler }) + const callback = spy() + + client.queue = [ + { + message: 'error', + callback + } + ] + + await t.notThrows(client.flush()) + await delay(5) + t.true(callback.calledOnce) +}) + test('flush - time out if configured', async t => { const client = createClient({ timeout: 500 }) const callback = spy() From 00c88ef91547f3e6ebd79b2e92e911c65fdc65fc Mon Sep 17 00:00:00 2001 From: Pooya Jaferian Date: Tue, 2 Aug 2022 10:59:36 -0700 Subject: [PATCH 2/2] v6.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6656333a..8e712c19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "analytics-node", - "version": "6.1.0", + "version": "6.2.0", "description": "The hassle-free way to integrate analytics into any Node.js application", "license": "MIT", "repository": "segmentio/analytics-node",