commercetools / commercetools/connect-application-kit

to catch async error, javascript requires await keyword

Open
#86 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
12
Forks
5
PR merge metrics
No merged PRs in 30d

Description

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

```typescript
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

```typescript
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.