In few videos I followed, they recommend to use express-async-handler but I am still not clear on it. But more importantly, how can one use it with sessions?
const proc = = expressAsyncHandler(async (req: Request, res: Response, next: NextFunction) => {
const session = await mongoose.startSession();
const newUser = await Data.create(..)
const newGroup = await Group.create(...)
session.commitTransaction()
}
now I could have an error in group so the whole thing should be rolled back. My error handler is defined in my entry file index.ts as follows
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
console.error(err.stack)
res.status(500).send('Error Found')
})
so my question is…how can i do session abort?