Add possibility to wrap routes in try catch
See original GitHub issueOvernightJS can currently not handle errors happening in asynchronous function calls and will throw UnhandledPromiseRejectionWarning
if the execution of this function is not wrapped in a try/catch
block.
Having to wrap every controller method in a try catch is repetition and clutter for the code though, it could be a good idea to implement, or atleast find a way to support a typical ‘handle async’ wrapper function for controller methods.
Wrapping controller methods (or providing an option to wrap them) into something like this at router creation time would fix this issue.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Express and async/await: shall I wrap the lot with try/catch?
Show activity on this post. You have two options: Wrap everything in a try-catch. Write your own error handling middleware as shown in...
Read more >Wrap every route in a try catch block; is it a good idea? : r/node
If possible only wrap 1-2 lines. putting try/catch blocks around large parts of code make it hard to debug and is a lazy/beginner...
Read more >How to wrap a route not found exception with the generic ...
I am trying to capture the exception when the route is not found and wrap the exception with the generic response model.
Read more >A Guide to Error Handling in Express.js | Scout APM Blog
When an error encounters synchronous code, Express catches it automatically. Here's an example of a route handler function where we simulate an ...
Read more >Using Express.js Routes for Promise-based Error Handling
Find out how to enable promise-based route code and centralize both error handling and normal-results handling in Express.js apps.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Working on it now. Will let you know when that decorator is finished. Thank you for the tips on how to make Overnight better. I don’t know if we can do a @ClassWrapper but we could definitely do a @Wrapper for methods.
Oh really. Is the example in the sample project not working?
https://github.com/seanpmaxwell/overnight/blob/master/sample-project/src/controllers/CustomRouterController.ts
https://github.com/seanpmaxwell/overnight/blob/master/sample-project/src/CustomRouterServer.ts