diff --git a/src/main/java/org/bdware/sc/boundry/JavaScriptEntry.java b/src/main/java/org/bdware/sc/boundry/JavaScriptEntry.java index 8769e57..efdbddc 100644 --- a/src/main/java/org/bdware/sc/boundry/JavaScriptEntry.java +++ b/src/main/java/org/bdware/sc/boundry/JavaScriptEntry.java @@ -1,6 +1,7 @@ package org.bdware.sc.boundry; import com.google.gson.JsonObject; +import groovy.util.ScriptException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bdware.sc.ContractProcess; @@ -328,7 +329,10 @@ public class JavaScriptEntry { return bo.toString(); } } - + //YancloudUtil.exceptionReturn({"msg":"missing arguments repoId ","code":1}); + public static void exceptionReturn(Object obj) throws ScriptReturnException { + throw new ScriptReturnException(JSONTool.convertMirrorToJson(obj)); + } /** * publish an event with semantic AT_LEAST_ONCE * diff --git a/src/main/java/org/bdware/sc/boundry/ScriptReturnException.java b/src/main/java/org/bdware/sc/boundry/ScriptReturnException.java new file mode 100644 index 0000000..2fddbf2 --- /dev/null +++ b/src/main/java/org/bdware/sc/boundry/ScriptReturnException.java @@ -0,0 +1,21 @@ +package org.bdware.sc.boundry; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +public class ScriptReturnException extends IllegalStateException { +// public String message1; +// public int code; + public JsonObject message; + public ScriptReturnException(JsonElement jsonElement) { + message=jsonElement.getAsJsonObject(); +// message=jo.get("msg").getAsString(); +// code=jo.get("code").getAsInt(); + } + +// @Override +// public String getMessage() { +// return this.message1; +// +// } +} diff --git a/src/main/java/org/bdware/sc/engine/DesktopEngine.java b/src/main/java/org/bdware/sc/engine/DesktopEngine.java index ed837e7..a1da6a9 100644 --- a/src/main/java/org/bdware/sc/engine/DesktopEngine.java +++ b/src/main/java/org/bdware/sc/engine/DesktopEngine.java @@ -18,6 +18,7 @@ import org.bdware.sc.bean.ContractRequest; import org.bdware.sc.bean.ProjectConfig; import org.bdware.sc.boundry.JavaScriptEntry; import org.bdware.sc.boundry.Resources; +import org.bdware.sc.boundry.ScriptReturnException; import org.bdware.sc.boundry.utils.UtilRegistry; import org.bdware.sc.encrypt.HardwareInfo; import org.bdware.sc.encrypt.HardwareInfo.OSType; @@ -550,7 +551,13 @@ public class DesktopEngine extends JSEngine { new JsonPrimitive("Action " + input.getAction() + " is not exported!")); } - } catch (ScriptException e) { + }catch (ScriptReturnException e){ + e.printStackTrace(); + return new ContractResult( + Status.Exception, + e.message); + } + catch (ScriptException e) { Throwable cause = e.getCause(); e.printStackTrace(); return new ContractResult(