From 614a89ff4fd7f3540ce4d9c0fd79efa5456f408a Mon Sep 17 00:00:00 2001 From: Kosmatoff Date: Mon, 13 Nov 2023 07:30:44 +0300 Subject: [PATCH] add norm --- .../repository/postgresql/postgres.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/microservices/transaction/repository/postgresql/postgres.go b/internal/microservices/transaction/repository/postgresql/postgres.go index 48d24381..9c68ec62 100644 --- a/internal/microservices/transaction/repository/postgresql/postgres.go +++ b/internal/microservices/transaction/repository/postgresql/postgres.go @@ -121,7 +121,10 @@ func (r *transactionRep) CreateTransaction(ctx context.Context, transaction *mod } defer func() { if err := tx.Rollback(ctx); err != nil { - r.logger.Fatal("Rollback transaction Error: %w", err) + if err = tx.Rollback(ctx); err != nil { + r.logger.Fatal("Rollback transaction Error: %w", err) + } + } }() @@ -197,9 +200,13 @@ func (r *transactionRep) UpdateTransaction(ctx context.Context, transaction *mod if err != nil { return fmt.Errorf("[repo] failed to start transaction: %w", err) } + defer func() { if err := tx.Rollback(ctx); err != nil { - r.logger.Fatal("Rollback transaction Error: %w", err) + if err = tx.Rollback(ctx); err != nil { + r.logger.Fatal("Rollback transaction Error: %w", err) + } + } }() @@ -291,9 +298,13 @@ func (r *transactionRep) DeleteTransaction(ctx context.Context, transactionID uu if err != nil { return fmt.Errorf("[repo] failed to start transaction: %w", err) } + defer func() { - if err != nil { - tx.Rollback(ctx) + if err := tx.Rollback(ctx); err != nil { + if err = tx.Rollback(ctx); err != nil { + r.logger.Fatal("Rollback transaction Error: %w", err) + } + } }()