forked from ligato/vpp-agent
/
errors.go
31 lines (25 loc) · 882 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package client
import (
"fmt"
"github.com/pkg/errors"
)
// errConnectionFailed implements an error returned when connection failed.
type errConnectionFailed struct {
host string
}
// Error returns a string representation of an errConnectionFailed
func (err errConnectionFailed) Error() string {
if err.host == "" {
return "Cannot connect to the agent. Is the agent running on this host?"
}
return fmt.Sprintf("Cannot connect to the agent at %s. Is the agent running?", err.host)
}
// IsErrConnectionFailed returns true if the error is caused by connection failed.
func IsErrConnectionFailed(err error) bool {
_, ok := errors.Cause(err).(errConnectionFailed)
return ok
}
// ErrorConnectionFailed returns an error with host in the error message when connection to agent failed.
func ErrorConnectionFailed(host string) error {
return errConnectionFailed{host: host}
}