优化默认请求消息
This commit is contained in:
parent
0cae2e48bc
commit
cb7721dd7a
@ -47,8 +47,10 @@ const (
|
||||
DefaultResponseMessageField = "message"
|
||||
// DefaultResponseDataField 默认数据字段
|
||||
DefaultResponseDataField = "data"
|
||||
// DefaultMessage 接口响应失败
|
||||
DefaultMessage = "api request fail"
|
||||
// DefaultFailMessage 接口响应失败
|
||||
DefaultFailMessage = "api request fail"
|
||||
// DefaultSuccessMessage 接口响应成功
|
||||
DefaultSuccessMessage = "api request success"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -306,9 +306,6 @@ func send(apiConfig *ApiRequestConfig, header map[string]string) *ApiResponse {
|
||||
}
|
||||
// 提取响应文案
|
||||
response.Message = gjson.GetBytes(responseByte, response.RequestConfig.ResponseMessageField).String()
|
||||
if len(response.Message) == 0 {
|
||||
response.Message = DefaultMessage
|
||||
}
|
||||
|
||||
// 判断响应状态码是否成功
|
||||
isBusinessCodeSuccess := false
|
||||
@ -319,6 +316,14 @@ func send(apiConfig *ApiRequestConfig, header map[string]string) *ApiResponse {
|
||||
}
|
||||
}
|
||||
|
||||
if len(response.Message) == 0 {
|
||||
if isBusinessCodeSuccess {
|
||||
response.Message = DefaultSuccessMessage
|
||||
} else {
|
||||
response.Message = DefaultFailMessage
|
||||
}
|
||||
}
|
||||
|
||||
if !isBusinessCodeSuccess {
|
||||
response.Exception = exception.New(ResponseCodeNotFound, response.Response.StatusCode, map[string]string{}, response.Message)
|
||||
return response
|
||||
|
Loading…
Reference in New Issue
Block a user