-
Notifications
You must be signed in to change notification settings - Fork 8
/
error.go
39 lines (34 loc) · 1.02 KB
/
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
package wxworkfinancesdk
import (
"fmt"
)
const (
// SDKErrMsg 错误消息
// SDKInitErrMsg sdk 初始化失败
SDKInitErrMsg = "sdk init failed"
// GetChatDataErrMsg 调用 GetChatData API 失败
GetChatDataErrMsg = "call GetChatData failed"
// DecryptErrMsg 调用 DecryptMessage API 失败
DecryptErrMsg = "call DecryptMessage API failed"
// GetMediaDataErrMsg 调用 GetMediaData API 失败
GetMediaDataErrMsg = "call GetMediaData API failed"
)
// Error SDK Error结构体
type Error struct {
// ErrCode 错误代码
ErrCode int `json:"errcode,omitempty"`
// ErrMsg 错误说明
ErrMsg string `json:"errmsg,omitempty"`
Hint string `json:"hint,omitempty"`
}
// Error implement error interface
func (e Error) Error() string {
if e.Hint != "" {
return fmt.Sprintf("errcode:%d, errmsg:%s, hint:%s", e.ErrCode, e.ErrMsg, e.Hint)
}
return fmt.Sprintf("errcode:%d, errmsg:%s", e.ErrCode, e.ErrMsg)
}
// NewSDKErr 新建错误
func NewSDKErr(code int, msg string) Error {
return Error{ErrCode: code, ErrMsg: msg}
}