From 36f9d7b8dbd1b9ac7b816c8a6c9ec34714c2f6d4 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Mon, 19 Jun 2023 12:17:45 +0800 Subject: [PATCH] routerrpc: make sure error is transformed into grpc error code --- lnrpc/routerrpc/router_server.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lnrpc/routerrpc/router_server.go b/lnrpc/routerrpc/router_server.go index 683e5663d..3dff8f50b 100644 --- a/lnrpc/routerrpc/router_server.go +++ b/lnrpc/routerrpc/router_server.go @@ -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 }