Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Change non-error log entries level in PaymentListener
Browse files Browse the repository at this point in the history
Some log entries with level equal `error` are not really errors. For
example: "Asset not allowed" should be logged as `info` and make
`PaymentListener` skip to the next payment.

Fix #73
  • Loading branch information
bartekn committed Sep 9, 2017
1 parent 74e1500 commit 17fda5a
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/github.com/stellar/gateway/listener/payment_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,32 +190,44 @@ func (pl *PaymentListener) onPayment(payment horizon.PaymentResponse) (err error
return
}

err = pl.process(payment)

if err != nil {
pl.log.WithFields(logrus.Fields{"err": err}).Error("Payment processed with errors")
dbPayment.Status = err.Error()
process, status := pl.shouldProcessPayment(payment)
if !process {
dbPayment.Status = status
pl.log.Info(status)
} else {
pl.log.Info("Payment successfully processed")
dbPayment.Status = "Success"
err = pl.process(payment)

if err != nil {
pl.log.WithFields(logrus.Fields{"err": err}).Error("Payment processed with errors")
dbPayment.Status = err.Error()
} else {
pl.log.Info("Payment successfully processed")
dbPayment.Status = "Success"
}
}

return pl.entityManager.Persist(dbPayment)
}

func (pl *PaymentListener) process(payment horizon.PaymentResponse) error {
// shouldProcessPayment returns false and text status if payment should not be processed
// (ex. asset is different than allowed assets).
func (pl *PaymentListener) shouldProcessPayment(payment horizon.PaymentResponse) (bool, string) {
if payment.Type != "payment" && payment.Type != "path_payment" {
return errors.New("Not a payment operation")
return false, "Not a payment operation"
}

if payment.To != pl.config.Accounts.ReceivingAccountID {
return errors.New("Operation sent not received")
return false, "Operation sent not received"
}

if !pl.isAssetAllowed(payment.AssetType, payment.AssetCode, payment.AssetIssuer) {
return errors.New("Asset not allowed")
return false, "Asset not allowed"
}

return true, ""
}

func (pl *PaymentListener) process(payment horizon.PaymentResponse) error {
err := pl.horizon.LoadMemo(&payment)
if err != nil {
return errors.Wrap(err, "Unable to load transaction memo")
Expand Down

0 comments on commit 17fda5a

Please sign in to comment.