Fix bugs in extension treatment REST API

Change-Id: If47f5ffce634617200e765be72c7898d984b0786
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java b/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java
index d04acf5..2b3c9d7 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java
@@ -241,12 +241,17 @@
         DeviceService deviceService = serviceDirectory.get(DeviceService.class);
         Device device = deviceService.getDevice(deviceId);
 
+        if (device == null) {
+            throw new IllegalArgumentException("Device not found");
+        }
+
         if (device.is(ExtensionTreatmentCodec.class)) {
             ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class);
             ObjectNode node = treatmentCodec.encode(extensionInstruction.extensionInstruction(), context);
             result.set(InstructionCodec.EXTENSION, node);
         } else {
-            log.warn("There is no codec to encode extension for device {}", deviceId.toString());
+            throw new IllegalArgumentException(
+                    "There is no codec to encode extension for device " + deviceId.toString());
         }
     }