Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit 58b79b4

Browse files
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.
1 parent 23823f9 commit 58b79b4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class Analytics {
298298
})
299299
.catch(err => {
300300
if (typeof this.errorHandler === 'function') {
301+
done(err)
301302
return this.errorHandler(err)
302303
}
303304

test.js

+17
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,23 @@ test('flush - do not throw on axios failure if errorHandler option is specified'
381381
t.true(errorHandler.calledOnce)
382382
})
383383

384+
test('flush - evoke callback when errorHandler option is specified', async t => {
385+
const errorHandler = spy()
386+
const client = createClient({ errorHandler })
387+
const callback = spy()
388+
389+
client.queue = [
390+
{
391+
message: 'error',
392+
callback
393+
}
394+
]
395+
396+
await t.notThrows(client.flush())
397+
await delay(5)
398+
t.true(callback.calledOnce)
399+
})
400+
384401
test('flush - time out if configured', async t => {
385402
const client = createClient({ timeout: 500 })
386403
const callback = spy()

0 commit comments

Comments
 (0)