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