修复相应类型设置错误的BUG

This commit is contained in:
白茶清欢 2025-04-29 14:40:04 +08:00
parent 0bd02dbd08
commit 146fbaf878
2 changed files with 10 additions and 6 deletions

View File

@ -95,7 +95,7 @@ func Send(ctx *gin.Context, code any, httpCode int, data any, responseOption *de
responseContentType := getResponseDataType(responseOption.ContentType)
responseInstance, _ := wrapper.NewJson(serialize.JSON.MarshalForStringIgnoreError(responseException.GetData()), &wrapper.Option{XmlName: responseOption.XmlName})
finalResponseData, _ := responseInstance.Marshal(responseContentType)
ctx.Data(responseException.GetHttpCode(), responseContentType, finalResponseData)
ctx.Data(responseException.GetHttpCode(), responseOption.ContentType, finalResponseData)
}
// getResponseDataType 获取相应数据类型
@ -138,7 +138,7 @@ func SendWithStatusOK(ctx *gin.Context, code any, data any) {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 13:08 2022/6/26
func SendWithException(ctx *gin.Context, e exception.IException, data map[string]any) {
func SendWithException(ctx *gin.Context, e exception.IException, data map[string]any, responseOption *define.ResponseOption) {
if nil == e {
e = exception.NewSuccess(data)
}
@ -152,7 +152,7 @@ func SendWithException(ctx *gin.Context, e exception.IException, data map[string
"e_data": e.GetData(),
"u_e_data": data,
}
Send(ctx, e.GetCode(), e.GetHttpCode(), outputData, nil)
Send(ctx, e.GetCode(), e.GetHttpCode(), outputData, responseOption)
}
// JSON ctx.JSON 的平替, 增加了数据是否已相应的标识

View File

@ -44,7 +44,9 @@ func RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
// 格式化验证错误的信息
err = GetValidateErr(formValue, err)
e = exception.NewFromError(400, err)
response.SendWithException(ctx, e, nil)
response.SendWithException(ctx, e, nil, &define.ResponseOption{
ContentType: "application/json;charset=utf-8",
})
ctx.Abort()
return
}
@ -97,7 +99,7 @@ func RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
if resList[1].IsNil() {
// 请求成功
isSuccess = true
response.Success(ctx, resList[0].Interface())
response.SuccessWithExtension(ctx, resList[0].Interface(), &define.ResponseOption{ContentType: "application/json;charset=utf-8"})
return
}
// 请求失败
@ -110,7 +112,9 @@ func RequestHandler(uriCfg UriConfig) gin.HandlerFunc {
"err": resList[1].Interface(),
})
}
response.SendWithException(ctx, e, nil)
response.SendWithException(ctx, e, nil, &define.ResponseOption{
ContentType: "application/json;charset=utf-8",
})
return
}
}