fix: http response body not close on status >= 400 (close #5163)

pull/5178/head
Andy Hsu 2023-09-05 15:46:16 +08:00
parent 6f6d20e1ba
commit f2f312b43a
1 changed files with 2 additions and 1 deletions

View File

@ -224,9 +224,10 @@ func RequestHttp(ctx context.Context, httpMethod string, headerOverride http.Hea
res.Header.Del("set-cookie") res.Header.Del("set-cookie")
if res.StatusCode >= 400 { if res.StatusCode >= 400 {
all, _ := io.ReadAll(res.Body) all, _ := io.ReadAll(res.Body)
_ = res.Body.Close()
msg := string(all) msg := string(all)
log.Debugln(msg) log.Debugln(msg)
return res, errors.New(msg) return nil, fmt.Errorf("http request [%s] failure,status: %d response:%s", URL, res.StatusCode, msg)
} }
return res, nil return res, nil
} }