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 "+
|
||||
"%x to switch: %v", paymentID, p.payment.PaymentHash, err)
|
||||
|
||||
// We must inspect the error to know whether it was
|
||||
// critical or not, to decide whether we should
|
||||
// continue trying.
|
||||
finalOutcome := p.router.processSendError(
|
||||
p.paySession, route, err,
|
||||
)
|
||||
if finalOutcome {
|
||||
// We must inspect the error to know whether it
|
||||
// was critical or not, to decide whether we
|
||||
// should continue trying.
|
||||
if err := p.handleSendError(route, err); err != nil {
|
||||
return [32]byte{}, nil, err
|
||||
}
|
||||
|
||||
// We make another payment attempt.
|
||||
p.lastError = err
|
||||
// Error was handled successfully, make a new
|
||||
// payment attempt.
|
||||
continue
|
||||
}
|
||||
|
||||
@ -206,22 +203,15 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
||||
log.Errorf("Attempt to send payment %x failed: %v",
|
||||
p.payment.PaymentHash, result.Error)
|
||||
|
||||
finalOutcome := p.router.processSendError(
|
||||
p.paySession, route, result.Error,
|
||||
)
|
||||
|
||||
if finalOutcome {
|
||||
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 must inspect the error to know whether it was
|
||||
// critical or not, to decide whether we should
|
||||
// continue trying.
|
||||
if err := p.handleSendError(route, result.Error); err != nil {
|
||||
return [32]byte{}, nil, err
|
||||
}
|
||||
|
||||
// We make another payment attempt.
|
||||
p.lastError = result.Error
|
||||
// Error was handled successfully, make a new payment
|
||||
// attempt.
|
||||
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