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/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", 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()