Skip to content

Commit

Permalink
Minor review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aloknerurkar committed Apr 15, 2021
1 parent 3e524b1 commit 9c57250
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
12 changes: 0 additions & 12 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 14 additions & 21 deletions pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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())
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 9c57250

Please sign in to comment.