接口非成功打印异常堆栈

- 接口非成功打印异常堆栈
- 支持开关控制是否打印
This commit is contained in:
白茶清欢 2024-09-30 11:47:04 +08:00
parent 8ceb818a24
commit 99ea9ba111
2 changed files with 7 additions and 1 deletions

View File

@ -36,6 +36,7 @@ type HttpHandleConfig struct {
RequestIsSuccessField string // 请求处理是否成功的标识 RequestIsSuccessField string // 请求处理是否成功的标识
ExtensionOutputField string // 扩展信息对外输出字段 ExtensionOutputField string // 扩展信息对外输出字段
EnableExtensionOutput bool EnableExtensionOutput bool
DisableDebugStackOutput bool // 禁用异常堆栈打印
} }
// ConvertDefaultConfig 覆盖默认配置 // ConvertDefaultConfig 覆盖默认配置
@ -55,6 +56,7 @@ func ConvertDefaultConfig(cfg *HttpHandleConfig) {
func GetHttpHandleConfig() *HttpHandleConfig { func GetHttpHandleConfig() *HttpHandleConfig {
return &HttpHandleConfig{ return &HttpHandleConfig{
EnableExtensionOutput: inputHttpHandleConfig.EnableExtensionOutput, EnableExtensionOutput: inputHttpHandleConfig.EnableExtensionOutput,
DisableDebugStackOutput: inputHttpHandleConfig.DisableDebugStackOutput,
RequestIDField: wrapper.TernaryOperator.String( RequestIDField: wrapper.TernaryOperator.String(
nil == inputHttpHandleConfig || inputHttpHandleConfig.RequestIDField == "", nil == inputHttpHandleConfig || inputHttpHandleConfig.RequestIDField == "",
consts.GinRequestIDField, consts.GinRequestIDField,

View File

@ -10,6 +10,7 @@ package response
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"runtime/debug"
"time" "time"
"git.zhangdeman.cn/zhangdeman/exception" "git.zhangdeman.cn/zhangdeman/exception"
@ -107,6 +108,9 @@ func SendWithException(ctx *gin.Context, e exception.IException, data any) {
if nil == e { if nil == e {
e = exception.NewSuccess(data) e = exception.NewSuccess(data)
} }
if !define.GetHttpHandleConfig().DisableDebugStackOutput {
debug.PrintStack()
}
outputData := map[string]any{ outputData := map[string]any{
"e_data": e.GetData(), "e_data": e.GetData(),
"u_e_data": data, "u_e_data": data,