Add toJsonMessage to Exception class 07/26907/1
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Tue, 26 Dec 2017 09:52:27 +0000 (15:22 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Tue, 26 Dec 2017 09:52:27 +0000 (15:22 +0530)
Issue-ID: CLI-66

Change-Id: Ic4553c28e20cd6db9add438339423dd458ab7d76
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java
framework/src/main/java/org/onap/cli/fw/error/OnapCommandException.java

index 3b2188f..a8fb9d3 100644 (file)
@@ -124,6 +124,10 @@ public class OnapCommandConstants {
     public static final String BOOLEAN_FALSE = "false";
 
     // Error message
+    public static final String ERROR= "error";
+    public static final String ERROR_CODE= "code";
+    public static final String ERROR_MESSAGE= "message";
+
     public static final String SCHEMA_INVALID_DEFAULT_PARAMS_SECTION = "Invalid default_parameter section";
     public static final String SCHEMA_FILE_EMPTY = "The schema file cann't be null or empty";
     public static final String SCHEMA_FILE_WRONG_EXTN = "Schema file should be '.yaml' extension";
index 3fecad0..5dffde5 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.onap.cli.fw.error;
 
+import org.onap.cli.fw.conf.OnapCommandConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -89,6 +90,12 @@ public class OnapCommandException extends Exception {
         return message;
     }
 
+    public String toJsonString() {
+        return "{\""+ OnapCommandConstants.ERROR + "\": {\""+
+                OnapCommandConstants.ERROR_CODE + "\": \"" + this.errorCode + "\", \""+
+                OnapCommandConstants.ERROR_MESSAGE + "\": \"" + this.errorMessage + "\"}}";
+    }
+
     public OnapCommandException(String errorCode, String errorMessage, Throwable e) {
         this(errorCode, errorMessage + ", " + e.getMessage());
         LOG.error(this.getMessage(), e);