添加在err方法输出data的函数
This commit is contained in:
@@ -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
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user