MCPcopy
hub / github.com/NVIDIA/aistore / checkResp

Method checkResp

api/client.go:269–299  ·  view source on GitHub ↗
(resp *http.Response)

Source from the content-addressed store, hash-verified

267}
268
269func (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}

Callers 3

DoHTTPRequestMethod · 0.95
doReaderMethod · 0.95
readRespMethod · 0.95

Calls 3

NewErrHTTPFunction · 0.92
ReadAllMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected