From 6cac44cfc7955832414a816d021de943a0d7e7ba Mon Sep 17 00:00:00 2001 From: Acha Bill <57879913+acha-bill@users.noreply.github.com> Date: Mon, 30 Oct 2023 14:08:35 +0100 Subject: [PATCH] fix: return 404 when no peers found during retrieval (#4436) --- pkg/api/bytes_test.go | 4 ++++ pkg/api/bzz.go | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/api/bytes_test.go b/pkg/api/bytes_test.go index 1a9b5bd0614..abae06bc2c6 100644 --- a/pkg/api/bytes_test.go +++ b/pkg/api/bytes_test.go @@ -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 diff --git a/pkg/api/bzz.go b/pkg/api/bzz.go index f73323b4799..d22fcff4dcb 100644 --- a/pkg/api/bzz.go +++ b/pkg/api/bzz.go @@ -9,6 +9,7 @@ import ( "encoding/hex" "errors" "fmt" + "github.com/ethersphere/bee/pkg/topology" "net/http" "path" "path/filepath" @@ -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 }