响应数据序列化出现异常, 触发panic
This commit is contained in:
parent
c5fa764807
commit
a677a8312b
@ -93,9 +93,14 @@ func Send(ctx *gin.Context, code any, httpCode int, data any, responseOption *de
|
|||||||
ctx.Set(responseConfig.ResponseDataField, responseData)
|
ctx.Set(responseConfig.ResponseDataField, responseData)
|
||||||
responseException := exception.New(code, responseData)
|
responseException := exception.New(code, responseData)
|
||||||
responseContentType := getResponseDataType(responseOption.ContentType)
|
responseContentType := getResponseDataType(responseOption.ContentType)
|
||||||
responseInstance, _ := wrapper.NewJson(serialize.JSON.MarshalForStringIgnoreError(responseException.Data()), &wrapper.Option{XmlName: responseOption.XmlName})
|
responseStr := serialize.JSON.MarshalForStringIgnoreError(responseException.Data())
|
||||||
finalResponseData, _ := responseInstance.Marshal(responseContentType)
|
if responseInstance, err := wrapper.NewJson(responseStr, &wrapper.Option{XmlName: responseOption.XmlName}); nil != err {
|
||||||
ctx.Data(http.StatusOK, responseOption.ContentType, finalResponseData)
|
// 接口处理成功, 数据序列化出现异常
|
||||||
|
panic(err.Error()) // 直接panic, 交给gin处理
|
||||||
|
} else {
|
||||||
|
finalResponseData, _ := responseInstance.Marshal(responseContentType)
|
||||||
|
ctx.Data(http.StatusOK, responseOption.ContentType, finalResponseData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getResponseDataType 获取相应数据类型
|
// getResponseDataType 获取相应数据类型
|
||||||
|
Loading…
x
Reference in New Issue
Block a user