From 763d44c72e63e8b0c798d7afb3299d55a9480ee9 Mon Sep 17 00:00:00 2001 From: demoManito <1430482733@qq.com> Date: Mon, 27 Mar 2023 18:03:58 +0800 Subject: [PATCH] refactor(contrib/registry/eureka): weird http code 200 judgment --- contrib/registry/eureka/client.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/contrib/registry/eureka/client.go b/contrib/registry/eureka/client.go index 3b985c5b1..98a8b063e 100644 --- a/contrib/registry/eureka/client.go +++ b/contrib/registry/eureka/client.go @@ -324,7 +324,11 @@ func (e *Client) request(ctx context.Context, method string, params []string, in _ = resp.Body.Close() }() - if output != nil && resp.StatusCode/100 == 2 { + if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNoContent { + if output == nil { + return false, nil + } + data, err := io.ReadAll(resp.Body) if err != nil { return false, err @@ -334,12 +338,7 @@ func (e *Client) request(ctx context.Context, method string, params []string, in return false, err } } - - if resp.StatusCode >= http.StatusBadRequest { - return false, fmt.Errorf("response Error %d", resp.StatusCode) - } - - return false, nil + return false, fmt.Errorf("response error %d", resp.StatusCode) } func (e *Client) do(ctx context.Context, method string, params []string, input io.Reader, output interface{}) error {