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