From c015841853c21f7b824820d447256bc86ad0de23 Mon Sep 17 00:00:00 2001 From: Anton Akentev Date: Thu, 1 Feb 2024 19:13:17 +0000 Subject: [PATCH] Add error handling for ns/pp clients --- nameservice/nameserviceclient/nameserviceclient.go | 6 ++++++ .../paymentserviceclient/paymentserviceclient.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/nameservice/nameserviceclient/nameserviceclient.go b/nameservice/nameserviceclient/nameserviceclient.go index 0641405b..84ec7d96 100644 --- a/nameservice/nameserviceclient/nameserviceclient.go +++ b/nameservice/nameserviceclient/nameserviceclient.go @@ -2,6 +2,7 @@ package nameserviceclient import ( "context" + "errors" "github.com/anyproto/any-sync/app" "github.com/anyproto/any-sync/app/logger" @@ -60,6 +61,11 @@ func New() AnyNsClientService { } func (s *service) doClient(ctx context.Context, fn func(cl nsp.DRPCAnynsClient) error) error { + if len(s.nodeconf.NamingNodePeers()) == 0 { + log.Error("no namingNode peers configured") + return errors.New("no namingNode peers configured") + } + // it will try to connect to the Naming Node // please enable "namingNode" type of node in the config (in the network.nodes array) peer, err := s.pool.Get(ctx, s.nodeconf.NamingNodePeers()[0]) diff --git a/paymentservice/paymentserviceclient/paymentserviceclient.go b/paymentservice/paymentserviceclient/paymentserviceclient.go index cc59b8f0..2d67a956 100644 --- a/paymentservice/paymentserviceclient/paymentserviceclient.go +++ b/paymentservice/paymentserviceclient/paymentserviceclient.go @@ -2,8 +2,10 @@ package paymentserviceclient import ( "context" + "errors" "github.com/anyproto/any-sync/app" + "github.com/anyproto/any-sync/app/logger" "github.com/anyproto/any-sync/net/pool" "github.com/anyproto/any-sync/net/rpc/rpcerr" "github.com/anyproto/any-sync/nodeconf" @@ -13,6 +15,8 @@ import ( const CName = "any-pp.drpcclient" +var log = logger.NewNamed(CName) + /* * This client component can be used to access the Any Payment Processing node * from other components. @@ -45,6 +49,12 @@ func New() AnyPpClientService { } func (s *service) doClient(ctx context.Context, fn func(cl pp.DRPCAnyPaymentProcessingClient) error) error { + if len(s.nodeconf.PaymentProcessingNodePeers()) == 0 { + log.Error("no payment processing peers configured") + + return errors.New("no paymentProcessingNode peers configured") + } + // it will try to connect to the Payment Node // please use "paymentProcessingNode" type of node in the config (in the network.nodes array) peer, err := s.pool.Get(ctx, s.nodeconf.PaymentProcessingNodePeers()[0])