diff --git a/pkg/api/bytes.go b/pkg/api/bytes.go index 312f3aa962..c2c14d21db 100644 --- a/pkg/api/bytes.go +++ b/pkg/api/bytes.go @@ -6,7 +6,6 @@ package api import ( "encoding/binary" - "encoding/json" "errors" "fmt" "net/http" @@ -16,7 +15,6 @@ import ( "github.com/ethersphere/bee/v2/pkg/cac" "github.com/ethersphere/bee/v2/pkg/file/redundancy" "github.com/ethersphere/bee/v2/pkg/jsonhttp" - "github.com/ethersphere/bee/v2/pkg/log" "github.com/ethersphere/bee/v2/pkg/postage" "github.com/ethersphere/bee/v2/pkg/storage" "github.com/ethersphere/bee/v2/pkg/swarm" @@ -194,7 +192,7 @@ func (s *Service) bytesHeadHandler(w http.ResponseWriter, r *http.Request) { Address swarm.Address `map:"address,resolve" validate:"required"` }{} if response := s.mapStructure(mux.Vars(r), &paths); response != nil { - respondWithError(w, http.StatusBadRequest, "Invalid path parameters", "Ensure address is provided", logger) + w.WriteHeader(http.StatusBadRequest) return } @@ -208,7 +206,7 @@ func (s *Service) bytesHeadHandler(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Debug("get root chunk failed", "chunk_address", address, "error", err) logger.Error(nil, "get root chunk failed") - respondWithError(w, http.StatusNotFound, "Chunk not found", "The requested chunk could not be retrieved", logger) + w.WriteHeader(http.StatusNotFound) return } @@ -224,16 +222,3 @@ func (s *Service) bytesHeadHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set(ContentLengthHeader, strconv.FormatInt(span, 10)) w.WriteHeader(http.StatusOK) // HEAD requests do not write a body } - -func respondWithError(w http.ResponseWriter, status int, title, detail string, logger log.Logger) { - w.Header().Set("Content-Type", "application/problem+json") - w.WriteHeader(status) - errorResponse := map[string]interface{}{ - "type": "about:blank", // Or a URI if you have one - "title": title, - "status": status, - "detail": detail, - } - logger.Error(nil, title) // Optionally log the error - json.NewEncoder(w).Encode(errorResponse) -}