diff --git a/node.go b/node.go index 9da1138..70ac72c 100644 --- a/node.go +++ b/node.go @@ -8,7 +8,11 @@ import ( "fmt" ) -var ErrServerNotFound = errors.New("server not found") +var ( + ErrServerNotFound = errors.New("server not found") + ErrNodesOffline = errors.New("one or more nodes are offline") + ErrNodesNotSearched = errors.New("one or more nodes could not be searched") +) type NodeStatus string @@ -59,12 +63,16 @@ func (c *NodeClient) FindServer(ctx context.Context, name, id string) (s *Server if err != nil { return } + nodeOffline := false + nodeNotSearched := false for _, node := range nl { if node.Status != NodeStatusOnline { + nodeOffline = true continue } sl, err := c.ListServers(ctx, node) if err != nil { + nodeNotSearched = true continue } for _, s := range sl { @@ -76,6 +84,12 @@ func (c *NodeClient) FindServer(ctx context.Context, name, id string) (s *Server } } } + if nodeOffline { + return nil, ErrNodesOffline + } + if nodeNotSearched { + return nil, ErrNodesNotSearched + } return nil, ErrServerNotFound }