diff --git a/api/v1/routes.go b/api/v1/routes.go index 053fa7c3..f8792e20 100644 --- a/api/v1/routes.go +++ b/api/v1/routes.go @@ -110,11 +110,6 @@ func postLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx err = worker.Process(ctx.Store, request.Layer.Name, request.Layer.ParentName, request.Layer.Path, request.Layer.Format) if err != nil { - if err == cerrors.ErrNotFound || err == worker.ErrParentUnknown { - writeResponse(w, r, http.StatusNotFound, LayerEnvelope{Error: &Error{err.Error()}}) - return postLayerRoute, http.StatusNotFound - } - if err == utils.ErrCouldNotExtract || err == utils.ErrExtractedFileTooBig || err == worker.ErrUnsupported { @@ -122,8 +117,7 @@ func postLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx return postLayerRoute, statusUnprocessableEntity } - _, badreq := err.(*cerrors.ErrBadRequest) - if badreq || err == utils.ErrCouldNotExtract || err == utils.ErrExtractedFileTooBig { + if _, badreq := err.(*cerrors.ErrBadRequest); badreq { writeResponse(w, r, http.StatusBadRequest, LayerEnvelope{Error: &Error{err.Error()}}) return postLayerRoute, http.StatusBadRequest } diff --git a/worker/detectors/data.go b/worker/detectors/data.go index 8b3366e5..dfbaa7e7 100644 --- a/worker/detectors/data.go +++ b/worker/detectors/data.go @@ -42,6 +42,9 @@ var ( dataDetectors = make(map[string]DataDetector) log = capnslog.NewPackageLogger("github.com/coreos/clair", "detectors") + + // ErrCouldNotFindLayer is returned when we could not download or open the layer file. + ErrCouldNotFindLayer = cerrors.NewBadRequestError("could not find layer") ) // RegisterDataDetector provides a way to dynamically register an implementation of a @@ -73,20 +76,17 @@ func DetectData(path string, format string, toExtract []string, maxFileSize int6 r, err := http.Get(path) if err != nil { log.Warningf("could not download layer: %s", err) - return nil, cerrors.ErrCouldNotDownload - } - if r.StatusCode == 404 { - return nil, cerrors.ErrNotFound + return nil, ErrCouldNotFindLayer } if math.Floor(float64(r.StatusCode/100)) != 2 { log.Warningf("could not download layer: got status code %d, expected 2XX", r.StatusCode) - return nil, cerrors.ErrCouldNotDownload + return nil, ErrCouldNotFindLayer } layerReader = r.Body } else { layerReader, err = os.Open(path) if err != nil { - return nil, cerrors.ErrNotFound + return nil, ErrCouldNotFindLayer } } defer layerReader.Close()