mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-09-23 03:36:40 +08:00
commit
e524547c7b
@ -3,12 +3,31 @@
|
|||||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||||
// @Author Ms <133814250@qq.com>
|
// @Author Ms <133814250@qq.com>
|
||||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||||
//
|
|
||||||
package consts
|
package consts
|
||||||
|
|
||||||
|
import "github.com/gogf/gf/v2/text/gstr"
|
||||||
|
|
||||||
// 错误解释
|
// 错误解释
|
||||||
const (
|
const (
|
||||||
ErrorORM = "sql执行异常"
|
ErrorORM = "sql执行异常"
|
||||||
ErrorNotData = "数据不存在"
|
ErrorNotData = "数据不存在"
|
||||||
ErrorRotaPointer = "指针转换异常"
|
ErrorRotaPointer = "指针转换异常"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 需要隐藏真实错误的Wrap,开启访问日志后仍然会将真实错误记录
|
||||||
|
var concealErrorSlice = []string{ErrorORM, ErrorNotData, ErrorRotaPointer}
|
||||||
|
|
||||||
|
// ErrorMessage 错误显示信息,非debug模式有效
|
||||||
|
func ErrorMessage(err error) (message string) {
|
||||||
|
if err == nil {
|
||||||
|
return "操作失败!~"
|
||||||
|
}
|
||||||
|
|
||||||
|
message = err.Error()
|
||||||
|
for _, e := range concealErrorSlice {
|
||||||
|
if gstr.Contains(message, e) {
|
||||||
|
return "操作失败,请稍后重试!~"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -104,11 +104,13 @@ func responseJson(r *ghttp.Request) {
|
|||||||
g.Log().Warningf(ctx, "exception:%v", err)
|
g.Log().Warningf(ctx, "exception:%v", err)
|
||||||
|
|
||||||
code = gerror.Code(err).Code()
|
code = gerror.Code(err).Code()
|
||||||
message = err.Error()
|
|
||||||
|
|
||||||
// 是否输出错误到页面
|
// 是否输出错误到页面
|
||||||
if g.Cfg().MustGet(ctx, "hotgo.debug", true).Bool() {
|
if g.Cfg().MustGet(ctx, "hotgo.debug", true).Bool() {
|
||||||
|
message = err.Error()
|
||||||
data = charset.ParseErrStack(err)
|
data = charset.ParseErrStack(err)
|
||||||
|
} else {
|
||||||
|
message = consts.ErrorMessage(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
data = r.GetHandlerResponse()
|
data = r.GetHandlerResponse()
|
||||||
|
@ -197,7 +197,7 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
|
|||||||
|
|
||||||
ipData, err := location.GetLocation(ctx, clientIp)
|
ipData, err := location.GetLocation(ctx, clientIp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Infof(ctx, "location.GetLocation clientIp:%v, err:%+v", clientIp, err)
|
g.Log().Debugf(ctx, "location.GetLocation clientIp:%v, err:%+v", clientIp, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ipData == nil {
|
if ipData == nil {
|
||||||
|
@ -31,7 +31,7 @@ func (s *sCronClient) Start(ctx context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Client == nil || config.Client.Cron == nil {
|
if config == nil || config.Client == nil || config.Client.Cron == nil {
|
||||||
g.Log().Errorf(ctx, "CronClient config is invalid")
|
g.Log().Errorf(ctx, "CronClient config is invalid")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user