Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to catch async error, javascript requires await keyword #86

Open
sfernengel opened this issue Aug 7, 2024 · 0 comments
Open

to catch async error, javascript requires await keyword #86

sfernengel opened this issue Aug 7, 2024 · 0 comments

Comments

@sfernengel
Copy link

Currently, in the Routes implementation, we have the following code as an example

serviceRouter.post('/', (req, res, next) => {
  logger.info('Service post message received');

  try {
    post(req, res);
  } catch (error) {
    next(error); 
  }
});

The post function being called is usually an async function, therefore if an error occurs during its execution, we won't be able to catch those errors in the catch method as it is.

Therefore I suggest we modify the code to catch async errors like this

serviceRouter.post('/', async (req, res, next) => {
  logger.info('Service post message received');

  try {
    await post(req, res);
  } catch (error) {
    next(error); 
  }
});

This change needs to be implemented for all connect applications and both for js and ts code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant