feathersjs / hooks

Async middleware for JavaScript and TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error hooks - re-throwing vs assigning context.error

KidkArolis opened this issue · comments

The behaviour of throwing in an error hook changed slightly from V4->V5.

If an error hook modifies context.error - that's all fine, the context is now updated and the error is re-thrown in regular.ts.
But if an error hook throws an error, that does not update context.error like it used to.

Perhaps this here should .catch(error => { context.error = error; throw context.error })

return runHook(hook, context, 'error').then(() => {
if (context.result === undefined && context.error !== undefined) {
throw context.error;
}
});
?