(resp *http.Response)
| 267 | } |
| 268 | |
| 269 | func (reqParams *ReqParams) checkResp(resp *http.Response) error { |
| 270 | if resp.StatusCode < http.StatusBadRequest { |
| 271 | return nil |
| 272 | } |
| 273 | if reqParams.BaseParams.Method == http.MethodHead { |
| 274 | if msg := resp.Header.Get(cos.HdrError); msg != "" { |
| 275 | httpErr := cmn.NewErrHTTP(nil, msg, resp.StatusCode) |
| 276 | httpErr.Method, httpErr.URLPath = reqParams.BaseParams.Method, reqParams.Path |
| 277 | return httpErr |
| 278 | } |
| 279 | } |
| 280 | var ( |
| 281 | httpErr *cmn.ErrHTTP |
| 282 | msg, _ = io.ReadAll(resp.Body) |
| 283 | ) |
| 284 | if reqParams.BaseParams.Method != http.MethodHead && resp.StatusCode != http.StatusServiceUnavailable { |
| 285 | if jsonErr := jsoniter.Unmarshal(msg, &httpErr); jsonErr == nil { |
| 286 | return httpErr |
| 287 | } |
| 288 | } |
| 289 | strMsg := string(msg) |
| 290 | if resp.StatusCode == http.StatusServiceUnavailable && strMsg == "" { |
| 291 | strMsg = fmt.Sprintf("[%s]: starting up, please try again later...", |
| 292 | http.StatusText(http.StatusServiceUnavailable)) |
| 293 | } |
| 294 | // HEAD request does not return the body - create http error |
| 295 | // 503 is also to be preserved |
| 296 | httpErr = cmn.NewErrHTTP(nil, strMsg, resp.StatusCode) |
| 297 | httpErr.Method, httpErr.URLPath = reqParams.BaseParams.Method, reqParams.Path |
| 298 | return httpErr |
| 299 | } |
no test coverage detected