fix(wallet): stop logging new idempotency keys as errors

GetTransactionByIdempotencyKey used First, so every wallet operation with a
key not seen before, which is the normal case, logged a "record not found"
error. It now uses Find with a limit and returns nil when nothing matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
efrilm
2026-09-30 08:47:37 +07:00
co-authored by Claude Opus 5.5
parent 2eb590caab
commit 6af97f5696
+9 -6
View File
@@ -188,17 +188,20 @@ func (r *walletRepository) CreateTransaction(ctx context.Context, walletTx *enti
}
func (r *walletRepository) GetTransactionByIdempotencyKey(ctx context.Context, key string) (*entities.WalletTransaction, error) {
var walletTx entities.WalletTransaction
// Find rather than First: a new key is the normal case, and First would log every
// one of them as a "record not found" error.
var walletTxs []entities.WalletTransaction
err := DBFromContext(ctx, r.db).WithContext(ctx).
Where("idempotency_key = ?", key).
First(&walletTx).Error
Limit(1).
Find(&walletTxs).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
return nil, fmt.Errorf("failed to get wallet transaction by idempotency key: %w", err)
}
return &walletTx, nil
if len(walletTxs) == 0 {
return nil, nil
}
return &walletTxs[0], nil
}
func (r *walletRepository) CreateLot(ctx context.Context, lot *entities.WalletLot) error {