diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransientElementMap.java b/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransientElementMap.java index 81842e69e..c9edd1a75 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransientElementMap.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransientElementMap.java @@ -24,6 +24,7 @@ import java.util.stream.Stream; import li.strolch.agent.api.ElementMap; import li.strolch.agent.api.StrolchAgent; +import li.strolch.exception.StrolchElementNotFoundException; import li.strolch.exception.StrolchException; import li.strolch.model.StrolchRootElement; import li.strolch.model.Version; @@ -88,7 +89,7 @@ public abstract class TransientElementMap implemen T t = getBy(tx, StrolchConstants.TEMPLATE, type); if (assertExists && t == null) { String msg = "The template with type \"{0}\" does not exist!"; //$NON-NLS-1$ - throw new StrolchException(MessageFormat.format(msg, type)); + throw new StrolchElementNotFoundException(MessageFormat.format(msg, type)); } if (t == null) @@ -117,7 +118,7 @@ public abstract class TransientElementMap implemen if (assertExists && t == null) { String msg = "The element with type \"{0}\" and id \"{1}\" does not exist!"; //$NON-NLS-1$ - throw new StrolchException(MessageFormat.format(msg, type, id)); + throw new StrolchElementNotFoundException(MessageFormat.format(msg, type, id)); } if (t == null) @@ -136,7 +137,7 @@ public abstract class TransientElementMap implemen T t = getBy(tx, type, id, false); if (assertExists && t == null) { String msg = "The element with type \"{0}\" and id \"{1}\" does not exist for param \"{2}\""; //$NON-NLS-1$ - throw new StrolchException(MessageFormat.format(msg, type, id, refP.getLocator())); + throw new StrolchElementNotFoundException(MessageFormat.format(msg, type, id, refP.getLocator())); } return t; } @@ -154,7 +155,7 @@ public abstract class TransientElementMap implemen T t = getBy(tx, type, id, false); if (assertExists && t == null) { String msg = "The element with type \"{0}\" and id \"{1}\" does not exist for param \"{2}\""; //$NON-NLS-1$ - throw new StrolchException(MessageFormat.format(msg, type, id, refP.getLocator())); + throw new StrolchElementNotFoundException(MessageFormat.format(msg, type, id, refP.getLocator())); } return t; }) // diff --git a/li.strolch.model/src/main/java/li/strolch/exception/StrolchElementNotFoundException.java b/li.strolch.model/src/main/java/li/strolch/exception/StrolchElementNotFoundException.java new file mode 100644 index 000000000..e10c77d6d --- /dev/null +++ b/li.strolch.model/src/main/java/li/strolch/exception/StrolchElementNotFoundException.java @@ -0,0 +1,12 @@ +package li.strolch.exception; + +public class StrolchElementNotFoundException extends StrolchModelException { + + public StrolchElementNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public StrolchElementNotFoundException(String message) { + super(message); + } +} diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java b/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java index 4d5542dd4..3139ddbe1 100644 --- a/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java +++ b/li.strolch.rest/src/main/java/li/strolch/rest/helper/ResponseUtil.java @@ -13,6 +13,7 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import li.strolch.exception.StrolchElementNotFoundException; import li.strolch.privilege.base.AccessDeniedException; import li.strolch.privilege.base.PrivilegeException; import li.strolch.privilege.base.PrivilegeModelException; @@ -140,6 +141,8 @@ public class ResponseUtil { status = Status.INTERNAL_SERVER_ERROR; } else if (t instanceof PrivilegeException) { status = Status.UNAUTHORIZED; + } else if (t instanceof StrolchElementNotFoundException) { + status = Status.NOT_FOUND; } else { status = Status.INTERNAL_SERVER_ERROR; } @@ -150,6 +153,8 @@ public class ResponseUtil { public static Response toResponse(Throwable t) { if (t instanceof AccessDeniedException) { return ResponseUtil.toResponse(Status.FORBIDDEN, t); + } else if (t instanceof StrolchElementNotFoundException) { + return ResponseUtil.toResponse(Status.NOT_FOUND, t); } else if (t instanceof PrivilegeModelException) { return ResponseUtil.toResponse(Status.INTERNAL_SERVER_ERROR, t); } else if (t instanceof PrivilegeException) {