From 691482d6a8865141d4c73eccd5ebfa3043cf6c92 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:33:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0http=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E7=A0=81=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 df13caf..5ea307c 100644 --- a/rpc.go +++ b/rpc.go @@ -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 +}