浏览代码

添加接口

yjp 3 年之前
父节点
当前提交
69532c9d19
共有 1 个文件被更改,包括 14 次插入1 次删除
  1. 14 1
      errors.go

+ 14 - 1
errors.go

@@ -25,6 +25,15 @@ var codeMap = map[uint32]string{
 	ErrCustomCode:       "自定义错误",
 }
 
+func ExplainCode(code uint32) string {
+	explain, ok := codeMap[code]
+	if !ok {
+		return codeMap[ErrUnknownCode]
+	}
+
+	return explain
+}
+
 func NewFromError(err error) error {
 	_, ok := err.(*Error)
 	if ok {
@@ -67,7 +76,11 @@ type Error struct {
 	error
 }
 
-func (err Error) Error() string {
+func (err *Error) Code() uint32 {
+	return err.code
+}
+
+func (err *Error) Error() string {
 	errMsg := fmt.Sprintf("错误代码: 0x%08x\n代码信息: %s\n%+v\n", err.code, codeMap[err.code], err.error)
 	return errMsg
 }