From 99ea9ba111bf0d84d9e61d1ce35fdbd11a63622a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 30 Sep 2024 11:47:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E9=9D=9E=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E5=BC=82=E5=B8=B8=E5=A0=86=E6=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 接口非成功打印异常堆栈 - 支持开关控制是否打印 --- define/response.go | 4 +++- response/response.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/define/response.go b/define/response.go index 09faa37..3ff6e63 100644 --- a/define/response.go +++ b/define/response.go @@ -36,6 +36,7 @@ type HttpHandleConfig struct { RequestIsSuccessField string // 请求处理是否成功的标识 ExtensionOutputField string // 扩展信息对外输出字段 EnableExtensionOutput bool + DisableDebugStackOutput bool // 禁用异常堆栈打印 } // ConvertDefaultConfig 覆盖默认配置 @@ -54,7 +55,8 @@ func ConvertDefaultConfig(cfg *HttpHandleConfig) { // Date : 16:55 2024/7/23 func GetHttpHandleConfig() *HttpHandleConfig { return &HttpHandleConfig{ - EnableExtensionOutput: inputHttpHandleConfig.EnableExtensionOutput, + EnableExtensionOutput: inputHttpHandleConfig.EnableExtensionOutput, + DisableDebugStackOutput: inputHttpHandleConfig.DisableDebugStackOutput, RequestIDField: wrapper.TernaryOperator.String( nil == inputHttpHandleConfig || inputHttpHandleConfig.RequestIDField == "", consts.GinRequestIDField, diff --git a/response/response.go b/response/response.go index 739d946..d6f249e 100644 --- a/response/response.go +++ b/response/response.go @@ -10,6 +10,7 @@ package response import ( "fmt" "net/http" + "runtime/debug" "time" "git.zhangdeman.cn/zhangdeman/exception" @@ -107,6 +108,9 @@ func SendWithException(ctx *gin.Context, e exception.IException, data any) { if nil == e { e = exception.NewSuccess(data) } + if !define.GetHttpHandleConfig().DisableDebugStackOutput { + debug.PrintStack() + } outputData := map[string]any{ "e_data": e.GetData(), "u_e_data": data,