2023-03-28 18:39:22 +00:00
// Copyright (c) HashiCorp, Inc.
2023-08-11 13:12:13 +00:00
// SPDX-License-Identifier: BUSL-1.1
2023-03-28 18:39:22 +00:00
2017-09-01 22:02:50 +00:00
package structs
import (
"errors"
"strings"
)
const (
errNoLeader = "No cluster leader"
errNoDCPath = "No path to datacenter"
2019-09-03 15:46:24 +00:00
errDCNotAvailable = "Remote DC has no server currently reachable"
2017-09-01 22:02:50 +00:00
errNoServers = "No known Consul servers"
errNotReadyForConsistentReads = "Not ready to serve consistent reads"
errSegmentsNotSupported = "Network segments are not supported in this version of Consul"
errRPCRateExceeded = "RPC rate limit exceeded"
2019-01-07 14:39:23 +00:00
errServiceNotFound = "Service not found: "
2020-07-01 00:49:13 +00:00
errQueryNotFound = "Query not found"
2021-01-04 19:05:23 +00:00
errLeaderNotTracked = "Raft leader not found in server lookup mapping"
2023-09-12 19:56:43 +00:00
errConnectNotEnabled = "Connect must be enabled in order to use this endpoint"
errRateLimited = "Rate limit reached, try again later" // Note: we depend on this error message in the gRPC ConnectCA.Sign endpoint (see: isRateLimitError).
errNotPrimaryDatacenter = "not the primary datacenter"
errStateReadOnly = "CA Provider State is read-only"
2017-09-01 22:02:50 +00:00
)
var (
ErrNoLeader = errors . New ( errNoLeader )
ErrNoDCPath = errors . New ( errNoDCPath )
ErrNoServers = errors . New ( errNoServers )
ErrNotReadyForConsistentReads = errors . New ( errNotReadyForConsistentReads )
ErrSegmentsNotSupported = errors . New ( errSegmentsNotSupported )
ErrRPCRateExceeded = errors . New ( errRPCRateExceeded )
2019-09-03 15:46:24 +00:00
ErrDCNotAvailable = errors . New ( errDCNotAvailable )
2020-07-01 00:49:13 +00:00
ErrQueryNotFound = errors . New ( errQueryNotFound )
2021-01-04 19:05:23 +00:00
ErrLeaderNotTracked = errors . New ( errLeaderNotTracked )
2023-09-12 19:56:43 +00:00
ErrConnectNotEnabled = errors . New ( errConnectNotEnabled )
ErrRateLimited = errors . New ( errRateLimited ) // Note: we depend on this error message in the gRPC ConnectCA.Sign endpoint (see: isRateLimitError).
ErrNotPrimaryDatacenter = errors . New ( errNotPrimaryDatacenter )
ErrStateReadOnly = errors . New ( errStateReadOnly )
2017-09-01 22:02:50 +00:00
)
2020-06-30 22:03:31 +00:00
func IsErrNoDCPath ( err error ) bool {
return err != nil && strings . Contains ( err . Error ( ) , errNoDCPath )
}
2020-07-01 00:49:13 +00:00
func IsErrQueryNotFound ( err error ) bool {
return err != nil && strings . Contains ( err . Error ( ) , errQueryNotFound )
}
2017-10-10 22:19:50 +00:00
func IsErrNoLeader ( err error ) bool {
return err != nil && strings . Contains ( err . Error ( ) , errNoLeader )
}
2017-09-01 22:02:50 +00:00
func IsErrRPCRateExceeded ( err error ) bool {
2017-10-10 22:19:50 +00:00
return err != nil && strings . Contains ( err . Error ( ) , errRPCRateExceeded )
2017-09-01 22:02:50 +00:00
}
2019-01-07 14:39:23 +00:00
func IsErrServiceNotFound ( err error ) bool {
return err != nil && strings . Contains ( err . Error ( ) , errServiceNotFound )
}