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.
This commit is contained in:
Joost Jager 2020-10-14 16:14:03 +02:00
parent d26001a69a
commit 856abade3d
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

View File

@ -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
}