Skip to content

Commit

Permalink
fix: invalid argument error on tx conflict in revert usage (#795)
Browse files Browse the repository at this point in the history
Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma authored Oct 16, 2024
1 parent 9194efb commit f1a0053
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/store/postgres/billing_transactions_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (r BillingTransactionRepository) CreateEntry(ctx context.Context, debitEntr
var pqErr *pgconn.PgError
if errors.As(err, &pqErr) && (pqErr.Code == "23505") { // handle unique key violations
if pqErr.ConstraintName == "billing_transactions_pkey" { // primary key violation
return fmt.Errorf("%w", credit.ErrAlreadyApplied)
return credit.ErrAlreadyApplied
}
// add other specific unique key violations here if needed
}
Expand All @@ -176,6 +176,13 @@ func (r BillingTransactionRepository) CreateEntry(ctx context.Context, debitEntr
if err = r.dbc.WithTimeout(ctx, TABLE_BILLING_TRANSACTIONS, "Create", func(ctx context.Context) error {
return r.dbc.QueryRowxContext(ctx, query, params...).StructScan(&creditModel)
}); err != nil {
var pqErr *pgconn.PgError
if errors.As(err, &pqErr) && (pqErr.Code == "23505") { // handle unique key violations
if pqErr.ConstraintName == "billing_transactions_pkey" { // primary key violation
return credit.ErrAlreadyApplied
}
// add other specific unique key violations here if needed
}
return fmt.Errorf("%w: %s", dbErr, err)
}

Expand Down

0 comments on commit f1a0053

Please sign in to comment.