feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
15.02k stars 745 forks source link

Method specific error hooks don't catch errors from before all hooks #3181

Open KidkArolis opened 1 year ago

KidkArolis commented 1 year ago

Steps to reproduce

If a service has the following hooks:

before: {
  all: [() => {
    throw new Error('boom')
  }]
},
error: {
  create: [context => console.log('After create', context.error.mesage)],
}

In V4 it outputs:

After create boom

In V5 the error.create hook is never called.

Expected behavior

V5 keeps backwards compatibility of the error hooks.

System configuration

Module versions: @feathersjs/feathers@5.0.4

Notes

Do you think this is worth fixing, or shall we work around it? I think the idea was to not break backwards compatibility for now. And generically, my expectation for an error[method] hook was that it will always be called for that method regardless of how other hooks are set up or where errors are thrown. Our specific issue is that we start some transactions in a before.all hook, but then if the before.all hook chain throws, the error.method specific transaction cleanup never happens.