From df20c73d6c5693ac1cb720b67ad5b1731a8c6104 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Tue, 26 Dec 2017 15:22:27 +0530 Subject: Add toJsonMessage to Exception class Issue-ID: CLI-66 Change-Id: Ic4553c28e20cd6db9add438339423dd458ab7d76 Signed-off-by: Kanagaraj Manickam k00365106 --- .../src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java | 4 ++++ .../src/main/java/org/onap/cli/fw/error/OnapCommandException.java | 7 +++++++ 2 files changed, 11 insertions(+) (limited to 'framework/src/main/java') diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java index 3b2188f3..a8fb9d37 100644 --- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java +++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java @@ -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"; diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandException.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandException.java index 3fecad02..5dffde5c 100644 --- a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandException.java +++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandException.java @@ -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); -- cgit 1.2.3-korg