Skip to content

Commit

Permalink
Fixed trans
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricTian committed Nov 5, 2019
1 parent 94c410a commit 42d19f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/app/bll/impl/internal/b_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func ExecTrans(ctx context.Context, transModel model.ITrans, fn TransFunc) error
return err
}

defer func() {
if r := recover(); r != nil {
_ = transModel.Rollback(ctx, trans)
panic(r)
}
}()

err = fn(icontext.NewTrans(ctx, trans))
if err != nil {
_ = transModel.Rollback(ctx, trans)
Expand Down
7 changes: 7 additions & 0 deletions internal/app/model/impl/gorm/internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func ExecTrans(ctx context.Context, db *gorm.DB, fn TransFunc) error {
return err
}

defer func() {
if r := recover(); r != nil {
_ = transModel.Rollback(ctx, trans)
panic(r)
}
}()

ctx = icontext.NewTrans(ctx, trans)
err = fn(ctx)
if err != nil {
Expand Down

0 comments on commit 42d19f1

Please sign in to comment.