diff --git a/index.js b/index.js index b261e2f..6697b9b 100644 --- a/index.js +++ b/index.js @@ -140,7 +140,7 @@ function dispatcher (hooks) { const send = createSend('subscription: ' + (ns ? ns + ':' + key : key)) cb = wrapHook(cb, subscriptionWraps) cb(send, function (err) { - applyHook(onErrorHooks, err) + applyHook(onErrorHooks, err, _state, createSend) }) return cb }) diff --git a/test.js b/test.js index da580d3..9ab0e30 100644 --- a/test.js +++ b/test.js @@ -424,12 +424,17 @@ tape('handlers: subscriptions', (t) => { }) t.test('should be able to emit an error', (t) => { - t.plan(2) + t.plan(4) const store = barracks({ - onError: (err) => t.equal(err.message, 'oh no!', 'err was received') + onError: (err, state, createSend) => { + t.equal(err.message, 'oh no!', 'err was received') + t.equal((state || {}).a, 1, 'state was passed') + t.equal(typeof createSend, 'function', 'createSend is a function') + } }) store.model({ + state: { a: 1 }, subscriptions: { mySub: (send, done) => { t.pass('sub initiated')