增加对业务状态码成功和失败的判断
This commit is contained in:
parent
04f782ac07
commit
30c1cc67c2
17
rpc.go
17
rpc.go
@ -246,6 +246,9 @@ func (r *request) Send(ctx *gin.Context, serviceFlag string, apiFlag string, par
|
|||||||
|
|
||||||
// 解析响应的业务数据
|
// 解析响应的业务数据
|
||||||
code, message, data = r.getCodeAndMessageAndData(apiConfig, responseBody)
|
code, message, data = r.getCodeAndMessageAndData(apiConfig, responseBody)
|
||||||
|
if !r.codeIsSuccess(code, apiConfig.SuccessCodeList) {
|
||||||
|
return fmt.Errorf("业务状态码异常 : %v -> %v", code, message)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,3 +359,17 @@ func (r *request) getCodeAndMessageAndData(apiConfig *Api, responseBody []byte)
|
|||||||
}
|
}
|
||||||
return code, message, data
|
return code, message, data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// codeIsSuccess 判断业务状态码是否为成功
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 18:27 2022/6/30
|
||||||
|
func (r *request) codeIsSuccess(input string, successCodeList []string) bool {
|
||||||
|
for _, item := range successCodeList {
|
||||||
|
if item == input {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user