-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
51 lines (42 loc) · 961 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
package errors
import (
"fmt"
)
type Error struct {
Status int
Code string
Type string
Message string
Values map[string]interface{}
}
func New(status int, msg string) *Error {
return &Error{Status: status, Message: msg}
}
func (e *Error) GetCode() string {
return e.Code
}
func (e *Error) GetType() string {
return e.Type
}
func (e *Error) GetMessage() string {
return e.Message
}
func (e *Error) GetStatus() int {
return e.Status
}
func (e *Error) SetValue(key string, value interface{}) {
if e.Values == nil {
e.Values = map[string]interface{}{}
}
e.Values[key] = value
}
func (e *Error) Error() string {
if e.Type == "" && e.Code == "" {
return fmt.Sprintf("[Error] %s", e.Message)
} else if e.Type == "" {
return fmt.Sprintf("[%s Error] %s", e.Type, e.Message)
} else if e.Code == "" {
return fmt.Sprintf("[Error: %s] %s", e.Code, e.Message)
}
return fmt.Sprintf("[%s Error: %s] %s", e.Type, e.Code, e.Message)
}