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

Commit

Permalink
Ensure callback is called when envoking errorHanlder
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thaley-atlassian committed Jul 27, 2022
1 parent 23823f9 commit 58b79b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 58b79b4

Please sign in to comment.