Skip to content

Commit

Permalink
fix: return 404 when no peers found during retrieval (#4436)
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill authored Oct 30, 2023
1 parent f5acd99 commit 6cac44c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/api/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func TestBytes(t *testing.T) {
}),
)
})

t.Run("not found", func(t *testing.T) {
jsonhttptest.Request(t, client, http.MethodGet, resource+"/"+swarm.EmptyAddress.String(), http.StatusNotFound)
})
}

// nolint:paralleltest,tparallel
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/ethersphere/bee/pkg/topology"
"net/http"
"path"
"path/filepath"
Expand Down Expand Up @@ -441,9 +442,9 @@ func (s *Service) serveManifestEntry(
func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *http.Request, reference swarm.Address, additionalHeaders http.Header, etag bool) {
reader, l, err := joiner.New(r.Context(), s.storer.Download(true), reference)
if err != nil {
if errors.Is(err, storage.ErrNotFound) {
if errors.Is(err, storage.ErrNotFound) || errors.Is(err, topology.ErrNotFound) {
logger.Debug("api download: not found ", "address", reference, "error", err)
logger.Error(nil, "not found")
logger.Error(nil, err.Error())
jsonhttp.NotFound(w, nil)
return
}
Expand Down

0 comments on commit 6cac44c

Please sign in to comment.