-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
56 lines (45 loc) · 882 Bytes
/
error.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
51
52
53
54
55
56
package core
type Error struct {
Code string
Msg string
Err interface{}
}
func (err Error) Error() string {
if err.Msg == "" {
return DefaultCodeMapping.GetCodeInfo(err.GetCode())
}
return err.Msg
}
func (err Error) GetMsg() string {
if err.Msg == "" {
err.Msg = DefaultCodeMapping.GetCodeInfo(err.GetCode())
if err.Msg == "" {
return "code:" + err.GetCode()
}
}
return err.Error()
}
func (err Error) GetCode() string {
if err.Code == "" {
return "500"
}
return err.Code
}
func (err Error) IsNil() bool {
return err.Msg == "" && err.Code == ""
}
func (err Error) GetDetail() interface{} {
if err.IsNil() {
return err.Err
}
return nil
}
func NewError(err error) Error {
return Error{Err: err}
}
func NewErrorCode(code string) Error {
return Error{Code: code}
}
func NewErrorStr(msg string) Error {
return Error{Code: "500", Msg: msg}
}