github.com/outbrain/consul@v1.4.5/agent/structs/errors.go (about)

     1  package structs
     2  
     3  import (
     4  	"errors"
     5  	"strings"
     6  )
     7  
     8  const (
     9  	errNoLeader                   = "No cluster leader"
    10  	errNoDCPath                   = "No path to datacenter"
    11  	errNoServers                  = "No known Consul servers"
    12  	errNotReadyForConsistentReads = "Not ready to serve consistent reads"
    13  	errSegmentsNotSupported       = "Network segments are not supported in this version of Consul"
    14  	errRPCRateExceeded            = "RPC rate limit exceeded"
    15  	errServiceNotFound            = "Service not found: "
    16  )
    17  
    18  var (
    19  	ErrNoLeader                   = errors.New(errNoLeader)
    20  	ErrNoDCPath                   = errors.New(errNoDCPath)
    21  	ErrNoServers                  = errors.New(errNoServers)
    22  	ErrNotReadyForConsistentReads = errors.New(errNotReadyForConsistentReads)
    23  	ErrSegmentsNotSupported       = errors.New(errSegmentsNotSupported)
    24  	ErrRPCRateExceeded            = errors.New(errRPCRateExceeded)
    25  )
    26  
    27  func IsErrNoLeader(err error) bool {
    28  	return err != nil && strings.Contains(err.Error(), errNoLeader)
    29  }
    30  
    31  func IsErrRPCRateExceeded(err error) bool {
    32  	return err != nil && strings.Contains(err.Error(), errRPCRateExceeded)
    33  }
    34  
    35  func IsErrServiceNotFound(err error) bool {
    36  	return err != nil && strings.Contains(err.Error(), errServiceNotFound)
    37  }