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
 }