Skip to content

Commit

Permalink
adding changes in #335 by @KayLay to handle transaction panic
Browse files Browse the repository at this point in the history
  • Loading branch information
paganotoni committed May 12, 2021
1 parent bef765a commit 71cb137
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ func (c *Connection) Transaction(fn func(tx *Connection) error) error {
if err != nil {
return err
}

defer func() {
if err := recover(); err != nil {
cn.TX.Rollback()
err = errors.Errorf("panic err %v", err)
}
}()

err = fn(cn)
if err != nil {
dberr = cn.TX.Rollback()
Expand Down

0 comments on commit 71cb137

Please sign in to comment.