routerrpc: make sure error is transformed into grpc error code

This commit is contained in:
yyforyongyu authored and Olaoluwa Osuntokun committed 2023-10-06 16:34:47 -07:00
1 parent 17a0a8de06
commit 36f9d7b8db
1 file changed
+13
+13
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
}