Skip to content

to catch async error, javascript requires await keyword #86

@sfernengel

Description

@sfernengel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions