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

Commit

Permalink
Merge pull request #347 from timhaley94/error-handler-callback
Browse files Browse the repository at this point in the history
Ensure callback is called when invoking errorHanlder
  • Loading branch information
pooyaj committed Aug 2, 2022
2 parents 23823f9 + 58b79b4 commit d62976f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -298,6 +298,7 @@ class Analytics {
})
.catch(err => {
if (typeof this.errorHandler === 'function') {
done(err)
return this.errorHandler(err)
}

Expand Down
17 changes: 17 additions & 0 deletions test.js
Expand Up @@ -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()
Expand Down

0 comments on commit d62976f

Please sign in to comment.