You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constwithCustomError=(hook,errorCreator)=>(context: any)=>{try{// if the hook does not produce an error, no need to throwconstres=hook(context);returnres;}catch(err){throwerrorCreator(context);}};
We can also use function composition to create a new disallow404 like so:
For the record, in case anyone else copies this, an await is required before the call to the internal hook.
constwithCustomError=(hook,errorCreator)=>(context: any)=>{try{// if the hook does not produce an error, no need to throwconstres=awaithook(context);returnres;}catch(err){throwerrorCreator(context);}};
Thanks for the suggestion and sorry for the late response. I started working on a massive rewrite of the package (#764). It's not released yet and will take a few weeks.
Activity
[-]Hook idea: withCustomError[/-][+][fature idea] Hook: withCustomError[/+]1valdis commentedon Feb 13, 2020
That would definitely be useful if an error needs to be, for example, localized.
michaelwiles commentedon Dec 28, 2023
+1
michaelwiles commentedon Dec 28, 2023
For the record, in case anyone else copies this, an await is required before the call to the internal hook.
fratzinger commentedon Feb 18, 2025
Thanks for the suggestion and sorry for the late response. I started working on a massive rewrite of the package (#764). It's not released yet and will take a few weeks.
This should be working then. I took a more drastical approach. I introduced a new hook called
throwIfIsProviderwhich basically works the same asdisallowbut has a more clear naming and has anerroroption to change the error, see https://github.com/feathersjs-ecosystem/feathers-hooks-common/blob/modernize/src/hooks/throw-if/throw-if-is-provider.ts