FTTH-50934 Fix the error response for the VGC NB Apis

Change-Id: Ibeb54b0a7a370a376b222b83154e2bb54250c863
diff --git a/internal/pkg/application/service.go b/internal/pkg/application/service.go
index 1061e21..5d7bc43 100644
--- a/internal/pkg/application/service.go
+++ b/internal/pkg/application/service.go
@@ -1110,11 +1110,13 @@
 
 // DelServiceWithPrefix - Deletes service with the provided prefix.
 // Added for DT/TT usecase with sadis replica interface
-func (va *VoltApplication) DelServiceWithPrefix(cntx context.Context, prefix string) {
+func (va *VoltApplication) DelServiceWithPrefix(cntx context.Context, prefix string) error {
+	var isServiceExist bool
 	va.ServiceByName.Range(func(key, value interface{}) bool {
 		srvName := key.(string)
 		vs := value.(*VoltService)
 		if strings.Contains(srvName, prefix) {
+			isServiceExist = true
 			va.DelService(cntx, srvName, true, nil, false)
 
 			vnetName := strconv.FormatUint(uint64(vs.SVlan), 10) + "-"
@@ -1127,6 +1129,11 @@
 		}
 		return true
 	})
+
+	if !isServiceExist {
+		return errorCodes.ErrServiceNotFound
+	}
+	return nil
 }
 
 // DelService delete a service form the application
@@ -2025,6 +2032,7 @@
 
 // ActivateService to activate pre-provisioned service
 func (va *VoltApplication) ActivateService(cntx context.Context, deviceID, portNo string, sVlan, cVlan of.VlanType, tpID uint16) error {
+	var isParmsInvalid bool
 	logger.Infow(ctx, "Service Activate Request ", log.Fields{"Device": deviceID, "Port": portNo})
 	device, err := va.GetDeviceFromPort(portNo)
 	if err != nil {
@@ -2043,9 +2051,11 @@
 		// If svlan if provided, then the tags and tpID of service has to be matching
 		if sVlan != of.VlanNone && (sVlan != vs.SVlan || cVlan != vs.CVlan || tpID != vs.TechProfileID) {
 			logger.Infow(ctx, "Service Activate Request Does not match", log.Fields{"Device": deviceID, "voltService": vs})
+			isParmsInvalid = true
 			return true
 		}
 		if portNo == vs.Port && !vs.IsActivated {
+			isParmsInvalid = false
 			p := device.GetPort(vs.Port)
 			if p == nil {
 				logger.Warnw(ctx, "Wrong device or port", log.Fields{"Device": deviceID, "Port": portNo})
@@ -2067,21 +2077,31 @@
 		}
 		return true
 	})
+
+	if isParmsInvalid {
+		return errorCodes.ErrInvalidParamInRequest
+	}
 	return nil
 }
 
 // DeactivateService to activate pre-provisioned service
 func (va *VoltApplication) DeactivateService(cntx context.Context, deviceID, portNo string, sVlan, cVlan of.VlanType, tpID uint16) error {
 	logger.Infow(ctx, "Service Deactivate Request ", log.Fields{"Device": deviceID, "Port": portNo})
+	var isServiceExist bool
+	var isParmsInvalid bool
+
 	va.ServiceByName.Range(func(key, value interface{}) bool {
 		vs := value.(*VoltService)
 		// If svlan if provided, then the tags and tpID of service has to be matching
 		logger.Infow(ctx, "Service Deactivate Request ", log.Fields{"Device": deviceID, "Port": portNo})
 		if sVlan != of.VlanNone && (sVlan != vs.SVlan || cVlan != vs.CVlan || tpID != vs.TechProfileID) {
 			logger.Infow(ctx, "condition not matched", log.Fields{"Device": deviceID, "Port": portNo, "sVlan": sVlan, "cVlan": cVlan, "tpID": tpID})
+			isParmsInvalid = true
 			return true
 		}
 		if portNo == vs.Port && vs.IsActivated {
+			isServiceExist = true
+			isParmsInvalid = false
 			vs.IsActivated = false
 			vs.DeactivateInProgress = true
 			va.ServiceByName.Store(vs.Name, vs)
@@ -2109,6 +2129,12 @@
 		}
 		return true
 	})
+
+	if isParmsInvalid {
+		return errorCodes.ErrInvalidParamInRequest
+	} else if !isServiceExist && !isParmsInvalid {
+		return errorCodes.ErrPortNotFound
+	}
 	return nil
 }
 
diff --git a/internal/pkg/application/service_test.go b/internal/pkg/application/service_test.go
index c687e55..1c66cb6 100644
--- a/internal/pkg/application/service_test.go
+++ b/internal/pkg/application/service_test.go
@@ -932,9 +932,8 @@
 				}
 			case "sVlan != of.VlanNone":
 				va.ServiceByName.Store("test_name", voltServiceTest)
-				if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
-					t.Errorf("VoltApplication.DeactivateService() error = %v, wantErr %v", err, tt.wantErr)
-				}
+				err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID)
+				assert.NotNil(t, err)
 			case GetDeviceFromPort_error:
 				va.ServiceByName.Store("test_name", voltServiceTest)
 				if err := va.DeactivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
@@ -1089,9 +1088,8 @@
 				va.PortsDisc.Store("test_port", voltPortTest)
 				va.DevicesDisc.Store(test_device, voltDevice)
 				va.ServiceByName.Store("test_name", voltServiceTest)
-				if err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID); (err != nil) != tt.wantErr {
-					t.Errorf("VoltApplication.ActivateService() error = %v, wantErr %v", err, tt.wantErr)
-				}
+				err := va.ActivateService(tt.args.cntx, tt.args.deviceID, tt.args.portNo, tt.args.sVlan, tt.args.cVlan, tt.args.tpID)
+				assert.NotNil(t, err)
 			}
 		})
 	}
@@ -2308,7 +2306,8 @@
 			}
 			va.VnetsBySvlan.Set(of.VlanAny, cuncurrentMap)
 			dbintf.EXPECT().DelVnet(gomock.Any(), gomock.Any()).Return(nil).Times(1)
-			va.DelServiceWithPrefix(tt.args.cntx, tt.args.prefix)
+			err := va.DelServiceWithPrefix(tt.args.cntx, tt.args.prefix)
+			assert.Nil(t, err)
 		})
 	}
 }
diff --git a/internal/pkg/errorcodes/errorcodes.go b/internal/pkg/errorcodes/errorcodes.go
index 68aa55c..db4ae51 100644
--- a/internal/pkg/errorcodes/errorcodes.go
+++ b/internal/pkg/errorcodes/errorcodes.go
@@ -76,6 +76,9 @@
 	ErrImageNotRegistered = status.Errorf(codes.FailedPrecondition, VolthaErrorMessageFormat, PrerequisiteNotMet, "Image is not registered")
 	// ErrImageDownloadInProgress is returned when the image download is in progress
 	ErrImageDownloadInProgress = status.Errorf(codes.FailedPrecondition, VolthaErrorMessageFormat, MethodNotAllowed, "Image download is in progress")
+
+	// ErrServiceNotFound is returned when the Service is not present in VOLTHA
+	ErrServiceNotFound = status.Errorf(codes.NotFound, VolthaErrorMessageFormat, ResourceNotFound, "Service not found")
 )
 
 // ConvertToVolthaErrorFormat converts the error to Voltha error format