-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
101 lines (82 loc) · 1.92 KB
/
errors.go
File metadata and controls
101 lines (82 loc) · 1.92 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import "os"
type LocalErrorCode int
const (
CodeWarning LocalErrorCode = 2
CodeError LocalErrorCode = 1
)
type LocalError interface {
Print()
PrintFatal()
SetAdditionalDetails(string)
}
type LocalErrorStruct struct {
err error
msg string
code LocalErrorCode
addDetails string
// hasError bool
}
func (e *LocalErrorStruct) Print() {
PrintError("Error code: %d\n", e.code)
PrintError("Error Msg : %s\n", e.msg)
if e.addDetails != "" {
PrintError("Details: %s\n", e.addDetails)
}
if e.err != nil {
PrintError("Error Stack: %s\n", e.err)
}
}
func (e *LocalErrorStruct) PrintFatal() {
e.Print()
os.Exit(1)
}
func (e *LocalErrorStruct) SetAdditionalDetails(d string) {
e.addDetails = d
}
// WithError add error to struct and returns a copy of LocalErrorStruct
func (e *LocalErrorStruct) WithError(err error) LocalError {
errCopy := *e
errCopy.err = err
return &errCopy
}
var ConfigFileReadErr = LocalErrorStruct{
code: CodeError,
msg: "Unable to read config file",
}
var ConfigFileUnmarshalErr = LocalErrorStruct{
code: CodeError,
msg: "Unable to unmarshal config file",
}
var MissingUserCredentialsErr = LocalErrorStruct{
code: CodeWarning,
msg: "Missing user credentials",
}
var RequestMarshalErr = LocalErrorStruct{
code: CodeError,
msg: "Unable to marshal request",
}
var UserLoginErr = LocalErrorStruct{
code: CodeError,
msg: "Unable to login user",
}
var RespBodyUnmarshalErr = LocalErrorStruct{
code: CodeError,
msg: "Unable to unmarshal response body",
}
var DataParseErr = LocalErrorStruct{
code: CodeError,
msg: "Unable to parse data",
}
var TokenReceiveErr = LocalErrorStruct{
code: CodeError,
msg: "Unable to get token from result. Format may be wrong",
}
var RequestExecErr = LocalErrorStruct{
code: CodeError,
msg: "Unable to do request",
}
var RequestRespWarn = LocalErrorStruct{
code: CodeWarning,
msg: "Request responded with non 200 status",
}