提交 9001749d authored 作者: mooncake's avatar mooncake

update

上级 0778551a
......@@ -4,7 +4,6 @@ package response
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"strconv"
"time"
......@@ -16,8 +15,6 @@ import (
"github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
)
const CustomErrorCode = 0
......@@ -264,23 +261,20 @@ func ErrorE(c *gin.Context, err *errcode.Error, data ...any) {
respJSONWith200(c, err.Code(), err.Msg(), data...)
}
var logf func(c *gin.Context, e error) string
func LogF(f func(c *gin.Context, e error) string) {
logf = f
}
func Error(c *gin.Context, err error) {
c.Set(ctxutils.KeyRspCode, 0)
msg := ""
if err != nil {
switch e := err.(type) {
case *xerror.BizError, *xerror.ParamError: //无需打印日志,在[middleware][logging]里会打印
msg = e.Error()
case *xerror.DBError: // 无需打印日志,在gorm层会打印日志
msg = "网络开小差了,请稍后再试~"
case *xerror.NetError, *xerror.CacheError, *xerror.RuntimeError: // 需要打印日志
logger.Error(fmt.Sprintf("[response]%s", err.Error()), ctxutils.GinTraceIDField(c))
msg = "网络开小差了,请稍后再试~"
default:
msg = e.Error()
logger.Error(fmt.Sprintf("[response]%s", err.Error()), ctxutils.GinTraceIDField(c))
msg = err.Error()
if logf != nil {
msg = logf(c, err)
}
}
respJSONWith200(c, CustomErrorCode, msg)
}
......@@ -129,3 +129,7 @@ func callers(skip ...int) stack {
}
return pcs[:runtime.Callers(n, pcs[:])]
}
func Callers(skip ...int) stack {
return callers()
}
......@@ -16,6 +16,27 @@ type Err struct {
code int // 如有必要,错误码。
}
func (x *Err) SetCaller(s stack) {
if x == nil {
return
}
x.stack = s
}
func (x *Err) SetText(s string) {
if x == nil {
return
}
x.text = s
}
func (x *Err) SetCode(s int) {
if x == nil {
return
}
x.code = s
}
type NetError struct {
Err
}
......
......@@ -13,11 +13,3 @@ func (err *Err) Code() int {
}
return err.code
}
// SetCode 使用指定 `code` 更新内部 `code` 。
func (err *Err) SetCode(code int) {
if err == nil {
return
}
err.code = code
}
......@@ -101,8 +101,12 @@ func ResolveSearchQuery(driver string, q any, condition Condition, pTName string
}
}
if t.Column == "" {
if qType.Field(i).Type.Kind() == reflect.Array && strings.HasSuffix(qType.Field(i).Name, "s") {
t.Column = snakeCase(strings.TrimSuffix(qType.Field(i).Name, "s"), false)
} else {
t.Column = snakeCase(qType.Field(i).Name, false)
}
}
if t.Table == "" {
t.Table = tname
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论