From 8c15046829d039ea5009ccfd26d1f4dc66fd47ad Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Fri, 27 Sep 2024 19:27:05 +0200 Subject: [PATCH] fix object not found log Signed-off-by: Pablo Chacin --- pkg/cache/server/server.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/cache/server/server.go b/pkg/cache/server/server.go index 3cc2851..6afd95c 100644 --- a/pkg/cache/server/server.go +++ b/pkg/cache/server/server.go @@ -63,29 +63,26 @@ func (s *CacheServer) Get(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "application/json") - // ensure errors are reported and logged - defer func() { - if resp.Error != "" { - s.log.Error(resp.Error) - _ = json.NewEncoder(w).Encode(resp) //nolint:errchkjson - } - }() - id := r.PathValue("id") if id == "" { w.WriteHeader(http.StatusBadRequest) resp.Error = ErrInvalidRequest.Error() + s.log.Error(resp.Error) + _ = json.NewEncoder(w).Encode(resp) //nolint:errchkjson return } object, err := s.cache.Get(context.Background(), id) //nolint:contextcheck if err != nil { if errors.Is(err, cache.ErrObjectNotFound) { + s.log.Debug(err.Error()) w.WriteHeader(http.StatusNotFound) } else { + s.log.Error(err.Error()) w.WriteHeader(http.StatusInternalServerError) } resp.Error = err.Error() + _ = json.NewEncoder(w).Encode(resp) //nolint:errchkjson return }