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

Commit d62976f

Browse files
authored
Merge pull request #347 from timhaley94/error-handler-callback
Ensure callback is called when invoking errorHanlder
2 parents 23823f9 + 58b79b4 commit d62976f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

index.js

Lines changed: 1 addition & 0 deletions
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

Lines changed: 17 additions & 0 deletions
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)