diff --git a/pkg/api/api.go b/pkg/api/api.go index 5dc9b744412..0c3775c4b11 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -67,20 +67,8 @@ var ( invalidRequest = errors.New("could not validate request") invalidContentType = errors.New("invalid content-type") invalidContentLength = errors.New("invalid content-length") - invalidAddress = errors.New("invalid hex address") - tagGetError = errors.New("cannot get or create tag") - tagSplitError = errors.New("tag done split failed") - tagIncError = errors.New("incrementing tag") directoryStoreError = errors.New("could not store directory") fileStoreError = errors.New("could not store file") - manifestGetError = errors.New("could not find manifest") - manifestCreateError = errors.New("could not create manifest") - manifestEntryError = errors.New("could not add entry to manifest") - manifestStoreError = errors.New("could not store manifest") - feedNotFound = errors.New("feed not found") - feedInvalidUpdate = errors.New("upable to parse feed update") - feedNoUpdate = errors.New("no update found") - feedMarshalIndexError = errors.New("marshal index") ) // Service is the API service interface. diff --git a/pkg/api/bzz.go b/pkg/api/bzz.go index 74f69f9d129..1ca9a3e4c96 100644 --- a/pkg/api/bzz.go +++ b/pkg/api/bzz.go @@ -76,7 +76,7 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Debugf("bzz upload file: get or create tag: %v", err) logger.Error("bzz upload file: get or create tag") - jsonhttp.InternalServerError(w, tagGetError) + jsonhttp.InternalServerError(w, nil) return } @@ -87,7 +87,7 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { s.logger.Debugf("bzz upload file: increment tag: %v", err) s.logger.Error("bzz upload file: increment tag") - jsonhttp.InternalServerError(w, tagIncError) + jsonhttp.InternalServerError(w, nil) return } } @@ -159,7 +159,7 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Debugf("bzz upload file: create manifest, file %q: %v", fileName, err) logger.Errorf("bzz upload file: create manifest, file %q", fileName) - jsonhttp.InternalServerError(w, manifestCreateError) + jsonhttp.InternalServerError(w, nil) return } @@ -171,7 +171,7 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Debugf("bzz upload file: adding metadata to manifest, file %q: %v", fileName, err) logger.Errorf("bzz upload file: adding metadata to manifest, file %q", fileName) - jsonhttp.InternalServerError(w, manifestEntryError) + jsonhttp.InternalServerError(w, nil) return } @@ -184,7 +184,7 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Debugf("bzz upload file: adding file to manifest, file %q: %v", fileName, err) logger.Errorf("bzz upload file: adding file to manifest, file %q", fileName) - jsonhttp.InternalServerError(w, manifestEntryError) + jsonhttp.InternalServerError(w, nil) return } @@ -210,7 +210,7 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Debugf("bzz upload file: manifest store, file %q: %v", fileName, err) logger.Errorf("bzz upload file: manifest store, file %q", fileName) - jsonhttp.InternalServerError(w, manifestStoreError) + jsonhttp.InternalServerError(w, nil) return } logger.Debugf("Manifest Reference: %s", manifestReference.String()) @@ -220,7 +220,7 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Debugf("bzz upload file: done split: %v", err) logger.Error("bzz upload file: done split failed") - jsonhttp.InternalServerError(w, tagSplitError) + jsonhttp.InternalServerError(w, nil) return } } @@ -255,7 +255,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Debugf("bzz download: parse address %s: %v", nameOrHex, err) logger.Error("bzz download: parse address") - jsonhttp.NotFound(w, invalidAddress) + jsonhttp.NotFound(w, nil) return } @@ -268,7 +268,7 @@ FETCH: if err != nil { logger.Debugf("bzz download: not manifest %s: %v", address, err) logger.Error("bzz download: not manifest") - jsonhttp.NotFound(w, manifestGetError) + jsonhttp.NotFound(w, nil) return } @@ -283,20 +283,20 @@ FETCH: if err != nil { logger.Debugf("bzz download: feed lookup: %v", err) logger.Error("bzz download: feed lookup") - jsonhttp.NotFound(w, feedNotFound) + jsonhttp.NotFound(w, "feed not found") return } if ch == nil { logger.Debugf("bzz download: feed lookup: no updates") logger.Error("bzz download: feed lookup") - jsonhttp.NotFound(w, feedNoUpdate) + jsonhttp.NotFound(w, "no update found") return } ref, _, err := parseFeedUpdate(ch) if err != nil { logger.Debugf("bzz download: parse feed update: %v", err) logger.Error("bzz download: parse feed update") - jsonhttp.InternalServerError(w, feedInvalidUpdate) + jsonhttp.InternalServerError(w, "parse feed update") return } address = ref @@ -305,7 +305,7 @@ FETCH: if err != nil { s.logger.Debugf("bzz download: marshal feed index: %v", err) s.logger.Error("bzz download: marshal index") - jsonhttp.InternalServerError(w, feedMarshalIndexError) + jsonhttp.InternalServerError(w, "marshal index") return } @@ -445,14 +445,7 @@ func (s *server) downloadHandler(w http.ResponseWriter, r *http.Request, referen // include additional headers for name, values := range additionalHeaders { - var v string - for _, value := range values { - if v != "" { - v += "; " - } - v += value - } - w.Header().Set(name, v) + w.Header().Set(name, strings.Join(values, "; ")) } if etag { w.Header().Set("ETag", fmt.Sprintf("%q", reference)) diff --git a/pkg/api/dirs.go b/pkg/api/dirs.go index 892421a9b8e..848cfc2ee3f 100644 --- a/pkg/api/dirs.go +++ b/pkg/api/dirs.go @@ -63,7 +63,7 @@ func (s *server) dirUploadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Debugf("bzz upload dir: get or create tag: %v", err) logger.Error("bzz upload dir: get or create tag") - jsonhttp.InternalServerError(w, tagGetError) + jsonhttp.InternalServerError(w, nil) return } @@ -91,7 +91,7 @@ func (s *server) dirUploadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Debugf("bzz upload dir: done split: %v", err) logger.Error("bzz upload dir: done split failed") - jsonhttp.InternalServerError(w, tagSplitError) + jsonhttp.InternalServerError(w, nil) return } }