diff --git a/httpclient/define.go b/httpclient/define.go index 0c8a70d..091f173 100644 --- a/httpclient/define.go +++ b/httpclient/define.go @@ -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 ( diff --git a/httpclient/request.go b/httpclient/request.go index 048b834..b269ab5 100644 --- a/httpclient/request.go +++ b/httpclient/request.go @@ -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