From 62c69335c299da08b93bfe55a7e7bb013c642b26 Mon Sep 17 00:00:00 2001 From: Matt Schallert Date: Tue, 4 Jun 2019 14:51:10 -0400 Subject: [PATCH] [api] placement delete: return 404 if not found --- src/query/api/v1/handler/placement/delete_all.go | 6 ++++++ src/query/api/v1/handler/placement/delete_all_test.go | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/query/api/v1/handler/placement/delete_all.go b/src/query/api/v1/handler/placement/delete_all.go index 6e4f6280c2..a0da824605 100644 --- a/src/query/api/v1/handler/placement/delete_all.go +++ b/src/query/api/v1/handler/placement/delete_all.go @@ -26,6 +26,7 @@ import ( "path" "time" + "github.com/m3db/m3/src/cluster/kv" "github.com/m3db/m3/src/query/api/v1/handler" "github.com/m3db/m3/src/query/util/logging" xhttp "github.com/m3db/m3/src/x/net/http" @@ -79,6 +80,11 @@ func (h *DeleteAllHandler) ServeHTTP(serviceName string, w http.ResponseWriter, } if err := service.Delete(); err != nil { + if err == kv.ErrNotFound { + logger.Info("cannot delete absent placement", zap.String("service", serviceName)) + xhttp.Error(w, err, http.StatusNotFound) + return + } logger.Error("unable to delete placement", zap.Error(err)) xhttp.Error(w, err, http.StatusInternalServerError) return diff --git a/src/query/api/v1/handler/placement/delete_all_test.go b/src/query/api/v1/handler/placement/delete_all_test.go index f0401947bb..5fdb231112 100644 --- a/src/query/api/v1/handler/placement/delete_all_test.go +++ b/src/query/api/v1/handler/placement/delete_all_test.go @@ -27,6 +27,7 @@ import ( "testing" "github.com/m3db/m3/src/cmd/services/m3query/config" + "github.com/m3db/m3/src/cluster/kv" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" @@ -64,5 +65,15 @@ func TestPlacementDeleteAllHandler(t *testing.T) { resp = w.Result() assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) + + // Test delete not found error + w = httptest.NewRecorder() + req = httptest.NewRequest(DeleteAllHTTPMethod, M3DBDeleteAllURL, nil) + require.NotNil(t, req) + mockPlacementService.EXPECT().Delete().Return(kv.ErrNotFound) + handler.ServeHTTP(serviceName, w, req) + + resp = w.Result() + assert.Equal(t, http.StatusNotFound, resp.StatusCode) }) }