From f30b5eb27aaec328e6d0cf55d358210d50ae1435 Mon Sep 17 00:00:00 2001 From: linstohu Date: Tue, 5 Dec 2023 13:22:08 +0800 Subject: [PATCH] feat: update --- utils/api.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/utils/api.go b/utils/api.go index 5f34541..ebdaefd 100644 --- a/utils/api.go +++ b/utils/api.go @@ -20,6 +20,8 @@ package utils import ( "bytes" "encoding/json" + "errors" + "fmt" "net/http" ) @@ -59,6 +61,16 @@ func (r *ApiResponse) ReadBody() ([]byte, error) { buf := new(bytes.Buffer) buf.ReadFrom(r.ApiRes.Body) + if r.ApiRes.StatusCode != http.StatusOK { + m := fmt.Sprintf("[HTTP]Failure: status code is NOT 200, %s %s, respond code=%d body=%s", + r.ApiReq.Method, + r.ApiReq.BaseURL+r.ApiReq.Path, + r.ApiRes.StatusCode, + buf.String(), + ) + return nil, errors.New(m) + } + r.Body = buf.Bytes() return r.Body, nil