question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add possibility to wrap routes in try catch

See original GitHub issue

OvernightJS 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
seanpmaxwellcommented, May 28, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found