优化home模块页面错误处理

This commit is contained in:
孟帅
2023-06-15 20:40:19 +08:00
parent 5abfeb5485
commit 2d0d7e5604
14 changed files with 509 additions and 397 deletions

View File

@@ -6,9 +6,11 @@
package charset
import (
"bytes"
"crypto/rand"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gutil"
r "math/rand"
"strings"
"time"
@@ -48,6 +50,16 @@ func ParseStack(st string) []string {
return stack
}
// SerializeStack 解析错误并序列化堆栈信息
func SerializeStack(err error) string {
buffer := bytes.NewBuffer(nil)
gutil.DumpTo(buffer, ParseErrStack(err), gutil.DumpOption{
WithType: false,
ExportedOnly: false,
})
return buffer.String()
}
// SubstrAfter 截取指定字符后的内容
func SubstrAfter(str string, symbol string) string {
comma := strings.Index(str, symbol)

View File

@@ -11,6 +11,7 @@ import (
"github.com/gogf/gf/v2/encoding/gbase64"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/glog"
"github.com/gogf/gf/v2/os/grpool"
"github.com/gogf/gf/v2/util/gconv"
@@ -46,6 +47,11 @@ func FilterMaskDemo(ctx context.Context, src g.Map) g.Map {
return src
}
// DefaultErrorTplContent 获取默认的错误模板内容
func DefaultErrorTplContent(ctx context.Context) string {
return gfile.GetContents(g.Cfg().MustGet(ctx, "viewer.paths").String() + "/error/default.html")
}
// DecryptText 解密文本
func DecryptText(text string) (string, error) {
str, err := gbase64.Decode([]byte(text))