添加在err方法输出data的函数

This commit is contained in:
Yun
2025-12-06 22:57:01 +08:00
parent 8ba1db76c0
commit c50605587a
2 changed files with 10 additions and 2 deletions
+4
View File
@@ -8,6 +8,10 @@ func GinError(ctx *gin.Context, err error) {
Error(ctx, ctx.Writer, err) Error(ctx, ctx.Writer, err)
} }
func GinErrorData(ctx *gin.Context, err error, data interface{}) {
ErrorWithData(ctx, ctx.Writer, err, data)
}
func GinErrorStr(ctx *gin.Context, msg string) { func GinErrorStr(ctx *gin.Context, msg string) {
ErrorStr(ctx, ctx.Writer, msg) ErrorStr(ctx, ctx.Writer, msg)
} }
+6 -2
View File
@@ -9,8 +9,8 @@ import (
"math" "math"
"net/http" "net/http"
"github.com/yuninks/langx"
"github.com/yuninks/errorx" "github.com/yuninks/errorx"
"github.com/yuninks/langx"
"github.com/zeromicro/go-zero/core/trace" "github.com/zeromicro/go-zero/core/trace"
) )
@@ -66,6 +66,10 @@ func SuccessWithPage(ctx context.Context, w http.ResponseWriter, data interface{
// 失败的响应 // 失败的响应
func Error(ctx context.Context, w http.ResponseWriter, err error) { func Error(ctx context.Context, w http.ResponseWriter, err error) {
ErrorWithData(ctx, w, err, "")
}
func ErrorWithData(ctx context.Context, w http.ResponseWriter, err error, data interface{}) {
code := op.defaultErrorCode code := op.defaultErrorCode
msg := "请求失败" msg := "请求失败"
if err != nil { if err != nil {
@@ -77,7 +81,7 @@ func Error(ctx context.Context, w http.ResponseWriter, err error) {
} }
msg = err.Error() msg = err.Error()
} }
ResponseCtx(ctx, w, code, msg, "") ResponseCtx(ctx, w, code, msg, data)
} }
func ErrorStr(ctx context.Context, w http.ResponseWriter, msg string) { func ErrorStr(ctx context.Context, w http.ResponseWriter, msg string) {