/
errors.go
50 lines (39 loc) · 977 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package tokens
import "go.aporeto.io/trireme-lib/collector"
const (
errCompressedTagMismatch = "Compressed tag mismatch"
errDatapathVersionMismatch = "Datapath version mismatch"
)
// ErrToken holds error message in string
type ErrToken struct {
message string
}
// newErrToken returns ErrToken handle
func newErrToken(message string) *ErrToken {
return &ErrToken{
message: message,
}
}
// Error returns error in string
func (e *ErrToken) Error() string {
return e.message
}
// Code returns collector reason
func (e *ErrToken) Code() string {
switch e.message {
case errCompressedTagMismatch:
return collector.CompressedTagMismatch
case errDatapathVersionMismatch:
return collector.DatapathVersionMismatch
default:
return collector.InvalidToken
}
}
// CodeFromErr returns the collector code from ErrToken
func CodeFromErr(err error) string {
errToken, ok := err.(*ErrToken)
if !ok {
return collector.InvalidToken
}
return errToken.Code()
}