You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2020/03/23 12:26:24 UTC

[servicecomb-kie] branch master updated: return 200 when key not found (#123)

This is an automated email from the ASF dual-hosted git repository.

tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-kie.git


The following commit(s) were added to refs/heads/master by this push:
     new d1c5135  return 200 when key not found (#123)
d1c5135 is described below

commit d1c5135d1c610a3a38cdac101ccbbcc268985547
Author: zhulijian <zh...@huawei.com>
AuthorDate: Mon Mar 23 20:26:17 2020 +0800

    return 200 when key not found (#123)
---
 pkg/model/kv.go                       |  4 ++--
 server/resource/v1/common.go          |  5 -----
 server/resource/v1/kv_resource.go     | 11 -----------
 server/service/mongo/kv/kv_service.go |  7 +++----
 4 files changed, 5 insertions(+), 22 deletions(-)

diff --git a/pkg/model/kv.go b/pkg/model/kv.go
index 71d20cd..5d87baa 100644
--- a/pkg/model/kv.go
+++ b/pkg/model/kv.go
@@ -29,8 +29,8 @@ type KVRequest struct {
 //KVResponse represents the key value list
 type KVResponse struct {
 	LabelDoc *LabelDocResponse `json:"label,omitempty"`
-	Total    int               `json:"total,omitempty"`
-	Data     []*KVDoc          `json:"data,omitempty"`
+	Total    int               `json:"total"`
+	Data     []*KVDoc          `json:"data"`
 }
 
 //LabelDocResponse is label struct
diff --git a/server/resource/v1/common.go b/server/resource/v1/common.go
index 2d48b79..3a7a151 100644
--- a/server/resource/v1/common.go
+++ b/server/resource/v1/common.go
@@ -242,11 +242,6 @@ func queryAndResponse(rctx *restful.Context, doc *model.KVDoc, offset, limit int
 	}
 	kv, err := service.KVService.List(rctx.Ctx, doc.Domain, doc.Project, opts...)
 	if err != nil {
-		if err == service.ErrKeyNotExists {
-			rctx.ReadResponseWriter().Header().Set(common.HeaderRevision, strconv.FormatInt(rev, 10))
-			WriteErrResponse(rctx, http.StatusNotFound, err.Error(), common.ContentTypeText)
-			return
-		}
 		WriteErrResponse(rctx, http.StatusInternalServerError, err.Error(), common.ContentTypeText)
 		return
 	}
diff --git a/server/resource/v1/kv_resource.go b/server/resource/v1/kv_resource.go
index 1f83c12..2c42bc5 100644
--- a/server/resource/v1/kv_resource.go
+++ b/server/resource/v1/kv_resource.go
@@ -288,12 +288,6 @@ func (r *KVResource) URLPatterns() []restful.Route {
 					},
 				},
 				{
-					Code: http.StatusNotFound,
-					Headers: map[string]goRestful.Header{
-						common.HeaderRevision: DocHeaderRevision,
-					},
-				},
-				{
 					Code:    http.StatusNotModified,
 					Message: "empty body",
 				},
@@ -316,11 +310,6 @@ func (r *KVResource) URLPatterns() []restful.Route {
 						common.HeaderRevision: DocHeaderRevision,
 					},
 				}, {
-					Code: http.StatusNotFound,
-					Headers: map[string]goRestful.Header{
-						common.HeaderRevision: DocHeaderRevision,
-					},
-				}, {
 					Code:    http.StatusNotModified,
 					Message: "empty body",
 				},
diff --git a/server/service/mongo/kv/kv_service.go b/server/service/mongo/kv/kv_service.go
index 99a11c8..e169dcc 100644
--- a/server/service/mongo/kv/kv_service.go
+++ b/server/service/mongo/kv/kv_service.go
@@ -172,7 +172,9 @@ func (s *Service) List(ctx context.Context, domain, project string, options ...s
 		return nil, err
 	}
 	defer cur.Close(ctx)
-	result := &model.KVResponse{}
+	result := &model.KVResponse{
+		Data: []*model.KVDoc{},
+	}
 	for cur.Next(ctx) {
 		curKV := &model.KVDoc{}
 		if err := cur.Decode(curKV); err != nil {
@@ -188,9 +190,6 @@ func (s *Service) List(ctx context.Context, domain, project string, options ...s
 		result.Data = append(result.Data, curKV)
 	}
 	result.Total = total
-	if len(result.Data) == 0 {
-		return nil, service.ErrKeyNotExists
-	}
 	return result, nil
 }