[feat] 优化错误提示

This commit is contained in:
2023-08-30 14:55:01 +08:00
parent afa9cba84b
commit 8f0e1f605d
2 changed files with 13 additions and 55 deletions
+3 -11
View File
@@ -1,10 +1,5 @@
package contracts
import (
"fmt"
"runtime"
)
// 定义错误码
type Errno struct {
Code int `json:"code"`
@@ -23,7 +18,7 @@ type Err struct {
}
func (err *Err) Error() string {
return fmt.Sprintf("Err - code: %d, message: %s, error: %s", err.Code, err.Msg, err.Errord)
return err.Errord
}
// 错误码设计
@@ -95,12 +90,9 @@ var (
// 使用 错误码 和 error 创建新的 错误
func NewErr(errno *Errno, err error) *Err {
stackBuf := make([]byte, 1024)
n := runtime.Stack(stackBuf[:], false)
return &Err{
Code: errno.Code,
Msg: err.Error(),
Errord: string(stackBuf[:n]),
Msg: errno.Error(),
Errord: err.Error(),
}
}