routerrpc: make sure error is transformed into grpc error code

This commit is contained in:
yyforyongyu 2023-06-19 12:17:45 +08:00 committed by Olaoluwa Osuntokun
parent 17a0a8de06
commit 36f9d7b8db

View File

@ -324,6 +324,19 @@ func (s *Server) SendPaymentV2(req *SendPaymentRequest,
// Init the payment in db.
paySession, shardTracker, err := s.cfg.Router.PreparePayment(payment)
if err != nil {
log.Errorf("SendPayment async error for payment %x: %v",
payment.Identifier(), err)
// Transform user errors to grpc code.
if errors.Is(err, channeldb.ErrPaymentExists) ||
errors.Is(err, channeldb.ErrPaymentInFlight) ||
errors.Is(err, channeldb.ErrAlreadyPaid) {
return status.Error(
codes.AlreadyExists, err.Error(),
)
}
return err
}