From 856abade3d7097ea06c93df0be06bf330a47231b Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 14 Oct 2020 16:14:03 +0200 Subject: [PATCH] routerrpc: map errors to grpc status code The 'payment already exists' case is common in restart scenarios. With this commit it is no longer necessary to string-match on the error message. Implementation is identical to SendPaymentV2. --- lnrpc/routerrpc/router_server.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lnrpc/routerrpc/router_server.go b/lnrpc/routerrpc/router_server.go index d6cd505d97..de64f92be8 100644 --- a/lnrpc/routerrpc/router_server.go +++ b/lnrpc/routerrpc/router_server.go @@ -375,6 +375,13 @@ func (s *Server) SendToRouteV2(ctx context.Context, return rpcAttempt, nil } + // Transform user errors to grpc code. + if err == channeldb.ErrPaymentInFlight || + err == channeldb.ErrAlreadyPaid { + + return nil, status.Error(codes.AlreadyExists, err.Error()) + } + return nil, err }