mercredi 28 avril 2021

Transaction cannot be rolled back because it has been finished with state: commit

let transaction
try{
    transaction = await ctx.app.model.transaction();
    const newPageResult = await pageService.add(addPageResult, { transaction });
    await transaction.commit();
    throw new Error("do rollback")

}catch(){
   transaction.rollback()
}
2021-04-28 17:02:53,801 ERROR 14904 [-/127.0.0.1/-/75306ms POST /page/copyPage] nodejs.Error: Transaction cannot be rolled back because it has been finished with state: commit
    at Transaction.rollback (/Users/my/work/node_modules/sequelize/lib/transaction.js:85:35)
    at PageController.copyPage (/Users/my/work/app/controller/pageController.ts:418:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)

I have read source code, If await transcation.commit(), this.finished must be "commit"

So If want to rollback must throw error... Here is the source code

enter image description here

enter image description here




Aucun commentaire:

Enregistrer un commentaire