import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService.WebClientResponse
 
 class RestconfConfigDeploy : AbstractScriptComponentFunction() {
     private val CONFIGLET_TEMPLATE_NAME = "config-assign"
     private val CONFIGLET_RESOURCE_PATH = "yang-ext:mount/mynetconf:netconflist"
     private val RESTCONF_SERVER_IDENTIFIER = "sdnc"
+    private val mapper = ObjectMapper()
     private val log = logger(AbstractScriptComponentFunction::class.java)
 
     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
                 val currentConfig: Any = restconfDeviceConfig(webclientService, deviceID, CONFIGLET_RESOURCE_PATH)
                 log.info("Current configuration subtree : $currentConfig")
                 //Apply configlet
-                restconfApplyDeviceConfig(webclientService, deviceID, CONFIGLET_RESOURCE_PATH,
+                val result = restconfApplyDeviceConfig(webclientService, deviceID, CONFIGLET_RESOURCE_PATH,
                         storedContentFromResolvedArtifactNB(resolutionKey, CONFIGLET_TEMPLATE_NAME),
-                        mutableMapOf("Content-Type" to "application/yang.patch+json"))
+                        mutableMapOf("Content-Type" to "application/yang.patch+json")) as WebClientResponse<*>
+
+                val jsonResult = mapper.readTree((result.body).toString())
+
+                if(jsonResult.get("ietf-yang-patch:yang-patch-status").get("errors") != null) {
+                    log.error("There was an error configuring device")
+                }  else {
+                    log.info("Device has been configured succesfully")
+                }
 
             } catch (err: Exception) {
                 log.error("an error occurred while configuring device {}", err)
 
 
 /**
  * Generic Configure function
+ * @return The WebClientResponse from the request
  */
 suspend fun AbstractScriptComponentFunction.restconfApplyDeviceConfig(
     webClientService: BlueprintWebClientService,
     configletResourcePath: String,
     configletToApply: Any,
     additionalHeaders: Map<String, String> = mutableMapOf("Content-Type" to "application/yang.patch+xml")
-) {
-
+): BlueprintWebClientService.WebClientResponse<String> {
     log.debug("headers: $additionalHeaders")
     log.info("configuring device: $deviceId, Configlet: $configletToApply")
     val applyConfigUrl = "restconf/config/network-topology:network-topology/topology/topology-netconf/node/" +
             "$deviceId/$configletResourcePath"
-    val result: Any = webClientService.exchangeResource("PATCH", applyConfigUrl, configletToApply as String, additionalHeaders)
-    log.info("Configuration application result: $result")
+    return webClientService.exchangeResource("PATCH", applyConfigUrl, configletToApply as String, additionalHeaders)
 }
 
 suspend fun AbstractScriptComponentFunction.restconfDeviceConfig(