Skip to content

Commit

Permalink
fix object not found log
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <[email protected]>
  • Loading branch information
pablochacin committed Sep 27, 2024
1 parent 7e5b931 commit 8c15046
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pkg/cache/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8c15046

Please sign in to comment.