u
This commit is contained in:
1 parent
d1b1aafc57
commit
0f1604c709
58 files changed
+15476
-25
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"base-framework/pkg/utils"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
@@ -125,7 +126,7 @@ func (c *Context) Get(key string) (interface{}, bool) {
|
||||
return val, ok
|
||||
}
|
||||
|
||||
// AddError 只记录错误对象
|
||||
// AddError 记录错误,自动包装 StackError
|
||||
func (c *Context) AddError(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
@@ -134,19 +135,23 @@ func (c *Context) AddError(err error) {
|
||||
if c.keys == nil {
|
||||
c.keys = make(map[string]interface{})
|
||||
}
|
||||
|
||||
if _, exists := c.keys["errors"]; !exists {
|
||||
c.keys["errors"] = []error{}
|
||||
c.keys["errors"] = []*utils.StackError{}
|
||||
}
|
||||
c.keys["errors"] = append(c.keys["errors"].([]error), err)
|
||||
|
||||
// 统一生成堆栈
|
||||
se := utils.WrapWithStack(err)
|
||||
c.keys["errors"] = append(c.keys["errors"].([]*utils.StackError), se)
|
||||
}
|
||||
|
||||
// Errors 获取所有错误
|
||||
func (c *Context) Errors() []error {
|
||||
// Errors 返回 []*utils.StackError
|
||||
func (c *Context) Errors() []*utils.StackError {
|
||||
if c.keys == nil {
|
||||
return nil
|
||||
}
|
||||
if errs, exists := c.keys["errors"]; exists {
|
||||
return errs.([]error)
|
||||
return errs.([]*utils.StackError)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user