@@ -147,7 +147,7 @@ func (r *Registry) GetRemoteHistory(imgID, registry string, token []string) ([]s
147147 res , err := doWithCookies (r .client , req )
148148 if err != nil || res .StatusCode != 200 {
149149 if res != nil {
150- return nil , fmt .Errorf ("Internal server error: %d trying to fetch remote history for %s" , res .StatusCode , imgID )
150+ return nil , utils . NewHTTPRequestError ( fmt .Sprintf ("Internal server error: %d trying to fetch remote history for %s" , res .StatusCode , imgID ), res )
151151 }
152152 return nil , err
153153 }
@@ -197,7 +197,7 @@ func (r *Registry) GetRemoteImageJSON(imgID, registry string, token []string) ([
197197 }
198198 defer res .Body .Close ()
199199 if res .StatusCode != 200 {
200- return nil , - 1 , fmt .Errorf ("HTTP code %d" , res .StatusCode )
200+ return nil , - 1 , utils . NewHTTPRequestError ( fmt .Sprintf ("HTTP code %d" , res .StatusCode ), res )
201201 }
202202
203203 imageSize , err := strconv .Atoi (res .Header .Get ("X-Docker-Size" ))
@@ -289,12 +289,12 @@ func (r *Registry) GetRepositoryData(indexEp, remote string) (*RepositoryData, e
289289 }
290290 defer res .Body .Close ()
291291 if res .StatusCode == 401 {
292- return nil , fmt .Errorf ("Please login first (HTTP code %d)" , res .StatusCode )
292+ return nil , utils . NewHTTPRequestError ( fmt .Sprintf ("Please login first (HTTP code %d)" , res .StatusCode ), res )
293293 }
294294 // TODO: Right now we're ignoring checksums in the response body.
295295 // In the future, we need to use them to check image validity.
296296 if res .StatusCode != 200 {
297- return nil , fmt .Errorf ("HTTP code: %d" , res .StatusCode )
297+ return nil , utils . NewHTTPRequestError ( fmt .Sprintf ("HTTP code: %d" , res .StatusCode ), res )
298298 }
299299
300300 var tokens []string
@@ -391,15 +391,15 @@ func (r *Registry) PushImageJSONRegistry(imgData *ImgData, jsonRaw []byte, regis
391391 if res .StatusCode != 200 {
392392 errBody , err := ioutil .ReadAll (res .Body )
393393 if err != nil {
394- return fmt .Errorf ("HTTP code %d while uploading metadata and error when trying to parse response body: %s" , res .StatusCode , err )
394+ return utils . NewHTTPRequestError ( fmt .Sprint ("HTTP code %d while uploading metadata and error when trying to parse response body: %s" , res .StatusCode , err ), res )
395395 }
396396 var jsonBody map [string ]string
397397 if err := json .Unmarshal (errBody , & jsonBody ); err != nil {
398398 errBody = []byte (err .Error ())
399399 } else if jsonBody ["error" ] == "Image already exists" {
400400 return ErrAlreadyExists
401401 }
402- return fmt .Errorf ("HTTP code %d while uploading metadata: %s" , res .StatusCode , errBody )
402+ return utils . NewHTTPRequestError ( fmt .Sprintf ("HTTP code %d while uploading metadata: %s" , res .StatusCode , errBody ), res )
403403 }
404404 return nil
405405}
@@ -427,9 +427,9 @@ func (r *Registry) PushImageLayerRegistry(imgID string, layer io.Reader, registr
427427 if res .StatusCode != 200 {
428428 errBody , err := ioutil .ReadAll (res .Body )
429429 if err != nil {
430- return "" , fmt .Errorf ("HTTP code %d while uploading metadata and error when trying to parse response body: %s" , res .StatusCode , err )
430+ return utils . NewHTTPRequestError ( fmt .Sprintf ("HTTP code %d while uploading metadata and error when trying to parse response body: %s" , res .StatusCode , err ), res )
431431 }
432- return "" , fmt .Errorf ("Received HTTP code %d while uploading layer: %s" , res .StatusCode , errBody )
432+ return utils . NewHTTPRequestError ( fmt .Sprintf ("Received HTTP code %d while uploading layer: %s" , res .StatusCode , errBody ), res )
433433 }
434434 return tarsumLayer .Sum (jsonRaw ), nil
435435}
@@ -463,7 +463,7 @@ func (r *Registry) PushRegistryTag(remote, revision, tag, registry string, token
463463 }
464464 res .Body .Close ()
465465 if res .StatusCode != 200 && res .StatusCode != 201 {
466- return fmt .Errorf ("Internal server error: %d trying to push tag %s on %s" , res .StatusCode , tag , remote )
466+ return utils . NewHTTPRequestError ( fmt .Sprintf ("Internal server error: %d trying to push tag %s on %s" , res .StatusCode , tag , remote ), res )
467467 }
468468 return nil
469469}
@@ -540,7 +540,7 @@ func (r *Registry) PushImageJSONIndex(indexEp, remote string, imgList []*ImgData
540540 if err != nil {
541541 return nil , err
542542 }
543- return nil , fmt .Errorf ("Error: Status %d trying to push repository %s: %s" , res .StatusCode , remote , errBody )
543+ return nil , utils . NewHTTPRequestError ( fmt .Sprintf ("Error: Status %d trying to push repository %s: %s" , res .StatusCode , remote , errBody ), res )
544544 }
545545 if res .Header .Get ("X-Docker-Token" ) != "" {
546546 tokens = res .Header ["X-Docker-Token" ]
@@ -564,7 +564,7 @@ func (r *Registry) PushImageJSONIndex(indexEp, remote string, imgList []*ImgData
564564 if err != nil {
565565 return nil , err
566566 }
567- return nil , fmt .Errorf ("Error: Status %d trying to push checksums %s: %s" , res .StatusCode , remote , errBody )
567+ return nil , utils . NewHTTPRequestError ( fmt .Sprintf ("Error: Status %d trying to push checksums %s: %s" , res .StatusCode , remote , errBody ), res )
568568 }
569569 }
570570
@@ -586,7 +586,7 @@ func (r *Registry) SearchRepositories(term string) (*SearchResults, error) {
586586 }
587587 defer res .Body .Close ()
588588 if res .StatusCode != 200 {
589- return nil , fmt .Errorf ("Unexepected status code %d" , res .StatusCode )
589+ return nil , utils . NewHTTPRequestError ( fmt .Sprintf ("Unexepected status code %d" , res .StatusCode ), res )
590590 }
591591 rawData , err := ioutil .ReadAll (res .Body )
592592 if err != nil {
0 commit comments