Student in ITE at Damascus University, AI Domain.
Backend Dev, Mobile Application Dev and interested in software's Domains like architected and Designs Systems.
If you want to handle error in express routes, you don't need to wrap the controller with a wrapper function, just use express-async-errors and create error middleware handling for handling errors.
Look to the docs for know how to use it
Versatile software developer skilled in JavaScript, TypeScript, MongoDB, PostgreSQL, MySQL, Render, Heroku, and AWS. Passionate about innovative solutions and team success.
I already use this, thanks very useful! Just thinking.. Can we add some kind of middle-ware code? Like how express-async-error solves it? Since we still need to repeat ourselves now on each API end-point.
If you want to handle error in express routes, you don't need to wrap the controller with a wrapper function, just use express-async-errors and create error middleware handling for handling errors.
Look to the docs for know how to use it
I have used this package too. Thanks for the contribution
@abhaysinghr1 Thanks for the comment
This was very helpful sir...
So with just that one handleCallBack function it can be applied to all the routes?
Yes, you will just follow the same syntax as shown in the getAllTrips controller function
Great post. Makes a cleaner code.
Thanks @wilmela. Glad it was helpful
I already use this, thanks very useful! Just thinking.. Can we add some kind of middle-ware code? Like how express-async-error solves it? Since we still need to repeat ourselves now on each API end-point.
Have been trying to find resources i can read about this, can you recommend one, I can't any in the express main documentation.
But this is really helpful, Thank you