npm install catch-async-expressWhen the function you write you do not know how to catch the error.
``typescript`
createUser = async (req: Request, res: Response) => {
const user = await userService.createUser(req.body);
res.status(httpStatus.CREATED).send(user);
};
- with npm
`command`
npm install catch-async-express `
- with yarncommand`
yarn add catch-async-express
`typescript``
createUser = catchAsync(async (req: Request, res: Response) => {
const user = await this.userService.createUser(req.body);
res.status(httpStatus.CREATED).send(user);
});