-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
39 lines (32 loc) · 848 Bytes
/
errors.go
File metadata and controls
39 lines (32 loc) · 848 Bytes
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
package errors
import "encoding/json"
// HappyCommonError 错误信息
type HappyCommonError struct {
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
RequestID string `json:"requestId,omitempty"`
}
func (h *HappyCommonError) Error() string {
b, _ := json.Marshal(h)
return string(b)
}
// NewHappyCommonError 创建一个新的错误
func NewHappyCommonError(code, message, requestID string) error {
return &HappyCommonError{
Code: code,
Message: message,
RequestID: requestID,
}
}
// GetCode 获取code代码
func (h *HappyCommonError) GetCode() string {
return h.Code
}
// GetMessage 获取错误信息
func (h *HappyCommonError) GetMessage() string {
return h.Message
}
// GetRequestID 获取请求特征ID
func (h *HappyCommonError) GetRequestID() string {
return h.RequestID
}