From 488dd84b79a985b02a22f9986fc8260350d0178d Mon Sep 17 00:00:00 2001
From: Gospodin Bodurov <gospodin@bodurov.net>
Date: Fri, 29 Nov 2019 11:13:59 +0200
Subject: [PATCH] Fix key storage agent

---
 handler/handler.go | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/handler/handler.go b/handler/handler.go
index 92bda0e..e6e7bea 100644
--- a/handler/handler.go
+++ b/handler/handler.go
@@ -95,7 +95,7 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest
 	if in.KeyType == api.KeyType_KT_EMPTY {
 		getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList,
 			"400", api.StatusType_ERROR, "KeyType cannot be empty")
-		return getKeyResponse, nil
+		return getKeyResponse, errors.New("KeyType cannot be empty")
 	}
 
 	key := &api.Key{}
@@ -106,13 +106,14 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest
 		getKeyResponse.Key = nil
 		getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList,
 			"500", api.StatusType_ERROR, err.Error())
-		return getKeyResponse, nil
+		return getKeyResponse, err.Error()
 	}
 
 	if errorsString != "" {
 		getKeyResponse.Key = nil
 		getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList,
 			"500", api.StatusType_ERROR, errorsString)
+		return nil, errors.New(errorsString)
 	}
 
 	if !hasData {
@@ -120,7 +121,7 @@ func (s *KeyStorageServerImpl) GetKey(ctx context.Context, in *api.GetKeyRequest
 		getKeyResponse.Key = nil
 		getKeyResponse.StatusList = utils.AddStatus(getKeyResponse.StatusList,
 			"500", api.StatusType_ERROR, err.Error())
-		return getKeyResponse, nil
+		return getKeyResponse, err.Error()
 	}
 
 	getKeyResponse.Key = key
@@ -139,13 +140,13 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
 	if in.Uuid == "root" {
 		setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList,
 			"400", api.StatusType_ERROR, "Can not set root CA keys")
-		return setKeyResponse, nil
+		return setKeyResponse, errors.New("Can not set root CA keys")
 	}
 
 	if in.KeyType == api.KeyType_KT_EMPTY {
 		setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList,
 			"400", api.StatusType_ERROR, "KeyType cannot be empty")
-		return setKeyResponse, nil
+		return setKeyResponse, errors.New("KeyType cannot be empty")
 	}
 
 	key := &api.Key{}
@@ -156,13 +157,13 @@ func (s *KeyStorageServerImpl) SetKey(ctx context.Context, in *api.SetKeyRequest
 			log.Printf("grpc call GetData to DataStorage failed: %s", err)
 			setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList,
 				"500", api.StatusType_ERROR, err.Error())
-			return setKeyResponse, nil
+			return setKeyResponse, err.Error()
 		}
 
 		if len(key.Content) > 0 {
 			setKeyResponse.StatusList = utils.AddStatus(setKeyResponse.StatusList,
 				"400", api.StatusType_ERROR, "Key is already set")
-			return setKeyResponse, nil
+			return setKeyResponse, errors.New("Key is already set")
 		}
 	}
 
-- 
GitLab