From 30c1cc67c2ebad7524fb41ff9922d1260e7c0c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 30 Jun 2022 18:30:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=A0=81=E6=88=90=E5=8A=9F=E5=92=8C=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/rpc.go b/rpc.go index 72f8c57..df13caf 100644 --- a/rpc.go +++ b/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) + if !r.codeIsSuccess(code, apiConfig.SuccessCodeList) { + return fmt.Errorf("业务状态码异常 : %v -> %v", code, message) + } return nil } @@ -356,3 +359,17 @@ func (r *request) getCodeAndMessageAndData(apiConfig *Api, responseBody []byte) } 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 +}