41 lines
782 B
Go
41 lines
782 B
Go
package xyshanghai
|
|
|
|
import "fmt"
|
|
|
|
// ErrorCode 定义错误码类型
|
|
type ErrorCode int
|
|
|
|
const (
|
|
// ErrCodeSuccess 成功
|
|
ErrCodeSuccess ErrorCode = 0
|
|
// ErrCodeFailure 失败
|
|
ErrCodeFailure ErrorCode = -1
|
|
)
|
|
|
|
// SDKError 自定义SDK错误
|
|
type SDKError struct {
|
|
Code ErrorCode
|
|
Message string
|
|
Err error
|
|
}
|
|
|
|
func (e *SDKError) Error() string {
|
|
if e.Err != nil {
|
|
return fmt.Sprintf("code=%d, message=%s, err=%v", e.Code, e.Message, e.Err)
|
|
}
|
|
return fmt.Sprintf("code=%d, message=%s", e.Code, e.Message)
|
|
}
|
|
|
|
// Unwrap 返回内部错误
|
|
func (e *SDKError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
// NewSDKError 创建SDK错误
|
|
func NewSDKError(code ErrorCode, message string, err error) *SDKError {
|
|
return &SDKError{
|
|
Code: code,
|
|
Message: message,
|
|
Err: err,
|
|
}
|
|
} |