优化异常堆栈打印
This commit is contained in:
@ -10,9 +10,6 @@ package response
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/exception"
|
||||
@ -106,33 +103,15 @@ func SendWithStatusOK(ctx *gin.Context, code any, data any) {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 13:08 2022/6/26
|
||||
func SendWithException(ctx *gin.Context, e exception.IException, data any) {
|
||||
func SendWithException(ctx *gin.Context, e exception.IException, data map[string]any) {
|
||||
if nil == e {
|
||||
e = exception.NewSuccess(data)
|
||||
}
|
||||
if !define.GetHttpHandleConfig().DisableDebugStackOutput {
|
||||
pcs := make([]uintptr, 128)
|
||||
n := runtime.Callers(2, pcs)
|
||||
|
||||
frames := runtime.CallersFrames(pcs[:n])
|
||||
|
||||
var sb strings.Builder
|
||||
for {
|
||||
frame, more := frames.Next()
|
||||
|
||||
sb.WriteString(frame.Function)
|
||||
sb.WriteByte('\n')
|
||||
sb.WriteByte('\t')
|
||||
sb.WriteString(frame.File)
|
||||
sb.WriteByte(':')
|
||||
sb.WriteString(strconv.Itoa(frame.Line))
|
||||
sb.WriteByte('\n')
|
||||
|
||||
if !more {
|
||||
break
|
||||
}
|
||||
if !define.GetHttpHandleConfig().DisableDebugStackOutput && nil != e {
|
||||
stack := e.GetStack()
|
||||
if len(stack) > 0 {
|
||||
fmt.Println(stack)
|
||||
}
|
||||
fmt.Println(sb.String())
|
||||
}
|
||||
outputData := map[string]any{
|
||||
"e_data": e.GetData(),
|
||||
|
Reference in New Issue
Block a user