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);}};
Hello guys,
I'm submitting the basic idea here and once you approve it, I'll add the PR with types and tests et al.
The hook is called
withCustomError
and it can be used to change errors thrown by other hooks.The scenario goes like this: I want to use the
disable
hook but return a 404 NotFound error instead of the default MethodNotAllowed error.Basically, instead of writing the following e.g:
We would wrap it in a
withCustomError
utility hook, like so:The basic code goes like this:
We can also use function composition to create a new
disallow404
like so:What do you think ?
The text was updated successfully, but these errors were encountered: