添加在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
+6 -2
View File
@@ -9,8 +9,8 @@ import (
"math"
"net/http"
"github.com/yuninks/langx"
"github.com/yuninks/errorx"
"github.com/yuninks/langx"
"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) {
ErrorWithData(ctx, w, err, "")
}
func ErrorWithData(ctx context.Context, w http.ResponseWriter, err error, data interface{}) {
code := op.defaultErrorCode
msg := "请求失败"
if err != nil {
@@ -77,7 +81,7 @@ func Error(ctx context.Context, w http.ResponseWriter, 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) {