u
This commit is contained in:
1 parent
d60be4a75b
commit
be8eaae7c5
24 files changed
+595
-232
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"base-go-v2/internal/errs"
|
||||
"base-go-v2/internal/utils/mapx"
|
||||
"base-go-v2/internal/utils/validate"
|
||||
"encoding/json"
|
||||
@@ -154,3 +155,35 @@ func (c *Context) Text(statusCode int, msg string) error {
|
||||
c.Abort()
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddError 记录错误,自动包装 StackError
|
||||
func (c *Context) AddError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if c.keys == nil {
|
||||
c.keys = make(map[string]interface{})
|
||||
}
|
||||
|
||||
if _, exists := c.keys["errors"]; !exists {
|
||||
c.keys["errors"] = []*errs.StackError{}
|
||||
}
|
||||
|
||||
// 统一生成堆栈
|
||||
se := errs.WrapWithStack(err)
|
||||
c.keys["errors"] = append(c.keys["errors"].([]*errs.StackError), se)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Errors 返回 []*utils.StackError
|
||||
func (c *Context) Errors() []*errs.StackError {
|
||||
if c.keys == nil {
|
||||
return nil
|
||||
}
|
||||
if err, exists := c.keys["errors"]; exists {
|
||||
return err.([]*errs.StackError)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user