From eba69937266bb85eb0ec5c5fd3a33605df184891 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Fri, 24 Mar 2023 17:36:36 +0800 Subject: [PATCH] ctx --- pkg/apiresp/gin.go | 2 +- pkg/apiresp/resp.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/apiresp/gin.go b/pkg/apiresp/gin.go index 17bcef6bc..e17f0144a 100644 --- a/pkg/apiresp/gin.go +++ b/pkg/apiresp/gin.go @@ -6,7 +6,7 @@ import ( ) func GinError(c *gin.Context, err error) { - c.JSON(http.StatusOK, ApiError(err)) + c.JSON(http.StatusOK, ParseError(err)) } func GinSuccess(c *gin.Context, data any) { diff --git a/pkg/apiresp/resp.go b/pkg/apiresp/resp.go index adc4e6f61..b724e1703 100644 --- a/pkg/apiresp/resp.go +++ b/pkg/apiresp/resp.go @@ -30,7 +30,7 @@ func isAllFieldsPrivate(v any) bool { return true } -func apiSuccess(data any) *ApiResponse { +func ApiSuccess(data any) *ApiResponse { if isAllFieldsPrivate(data) { return &ApiResponse{} } @@ -40,6 +40,9 @@ func apiSuccess(data any) *ApiResponse { } func ParseError(err error) *ApiResponse { + if err == nil { + return ApiSuccess(nil) + } unwrap := errs.Unwrap(err) if codeErr, ok := unwrap.(errs.CodeError); ok { resp := ApiResponse{ErrCode: codeErr.Code(), ErrMsg: codeErr.Msg(), ErrDlt: codeErr.Detail()}