增加http状态码的判断

This commit is contained in:
白茶清欢 2022-06-30 18:33:18 +08:00
parent 30c1cc67c2
commit 691482d6a8

17
rpc.go
View File

@ -244,6 +244,9 @@ func (r *request) Send(ctx *gin.Context, serviceFlag string, apiFlag string, par
return err
}
if !r.httpCodeIsSuccess(response.StatusCode, apiConfig.SuccessHttpCodeList) {
return fmt.Errorf("HTTP状态码异常 : %v -> %v", response.StatusCode, response.Status)
}
// 解析响应的业务数据
code, message, data = r.getCodeAndMessageAndData(apiConfig, responseBody)
if !r.codeIsSuccess(code, apiConfig.SuccessCodeList) {
@ -373,3 +376,17 @@ func (r *request) codeIsSuccess(input string, successCodeList []string) bool {
}
return false
}
// httpCodeIsSuccess http状态码是否为成功
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 18:31 2022/6/30
func (r *request) httpCodeIsSuccess(input int, successCodeList []int) bool {
for _, item := range successCodeList {
if item == input {
return true
}
}
return false
}