routing/payment_lifecycle: extract error handling into method
This commit is contained in:
parent
83bfaa4fb4
commit
e9b2182cdc
@ -131,18 +131,15 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
|||||||
log.Errorf("Failed sending attempt %d for payment "+
|
log.Errorf("Failed sending attempt %d for payment "+
|
||||||
"%x to switch: %v", paymentID, p.payment.PaymentHash, err)
|
"%x to switch: %v", paymentID, p.payment.PaymentHash, err)
|
||||||
|
|
||||||
// We must inspect the error to know whether it was
|
// We must inspect the error to know whether it
|
||||||
// critical or not, to decide whether we should
|
// was critical or not, to decide whether we
|
||||||
// continue trying.
|
// should continue trying.
|
||||||
finalOutcome := p.router.processSendError(
|
if err := p.handleSendError(route, err); err != nil {
|
||||||
p.paySession, route, err,
|
|
||||||
)
|
|
||||||
if finalOutcome {
|
|
||||||
return [32]byte{}, nil, err
|
return [32]byte{}, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// We make another payment attempt.
|
// Error was handled successfully, make a new
|
||||||
p.lastError = err
|
// payment attempt.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,22 +203,15 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
|||||||
log.Errorf("Attempt to send payment %x failed: %v",
|
log.Errorf("Attempt to send payment %x failed: %v",
|
||||||
p.payment.PaymentHash, result.Error)
|
p.payment.PaymentHash, result.Error)
|
||||||
|
|
||||||
finalOutcome := p.router.processSendError(
|
// We must inspect the error to know whether it was
|
||||||
p.paySession, route, result.Error,
|
// critical or not, to decide whether we should
|
||||||
)
|
// continue trying.
|
||||||
|
if err := p.handleSendError(route, result.Error); err != nil {
|
||||||
if finalOutcome {
|
return [32]byte{}, nil, err
|
||||||
log.Errorf("Payment %x failed with "+
|
|
||||||
"final outcome: %v",
|
|
||||||
p.payment.PaymentHash, result.Error)
|
|
||||||
|
|
||||||
// Terminal state, return the error we
|
|
||||||
// encountered.
|
|
||||||
return [32]byte{}, nil, result.Error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We make another payment attempt.
|
// Error was handled successfully, make a new payment
|
||||||
p.lastError = result.Error
|
// attempt.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,3 +225,25 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleSendError inspects the given error and determines whether we should
|
||||||
|
// make another payment attempt.
|
||||||
|
func (p *paymentLifecycle) handleSendError(rt *route.Route,
|
||||||
|
sendErr error) error {
|
||||||
|
|
||||||
|
finalOutcome := p.router.processSendError(
|
||||||
|
p.paySession, rt, sendErr,
|
||||||
|
)
|
||||||
|
|
||||||
|
if finalOutcome {
|
||||||
|
log.Errorf("Payment %x failed with final outcome: %v",
|
||||||
|
p.payment.PaymentHash, sendErr)
|
||||||
|
|
||||||
|
// Terminal state, return the error we encountered.
|
||||||
|
return sendErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// We get ready to make another payment attempt.
|
||||||
|
p.lastError = sendErr
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user