diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/exception/ErrorCode.java b/io/src/main/java/org/gcube/resourcemanagement/manager/exception/ErrorCode.java new file mode 100644 index 0000000..58398d5 --- /dev/null +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/exception/ErrorCode.java @@ -0,0 +1,16 @@ +/** + * + */ +package org.gcube.resourcemanagement.manager.exception; + +/** + * Interface for error codes. + * + * @author Manuele Simi (ISTI CNR) + * + */ +public interface ErrorCode { + public int getId(); + + public String getMsg(); +} diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/exception/ExceptionCode.java b/io/src/main/java/org/gcube/resourcemanagement/manager/exception/ExceptionCode.java new file mode 100644 index 0000000..ce28bd9 --- /dev/null +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/exception/ExceptionCode.java @@ -0,0 +1,31 @@ +package org.gcube.resourcemanagement.manager.exception; + +/** + * Exception codes handled with {@link RMException}. + * + * @author Manuele Simi (ISTI CNR) + * + */ +public enum ExceptionCode implements ErrorCode { + + INVALID_REQUEST(0, "The request is invalid"), + MISSING_PARAMETER(1, "Required query parameter is missing"), + MISSING_HEADER(2, "Required header is missing"), + CONTEXT_ALREADY_EXIST(3, "Required header is missing"); + + private final int id; + private final String msg; + + ExceptionCode(int id, String msg) { + this.id = id; + this.msg = msg; + } + + public int getId() { + return this.id; + } + + public String getMsg() { + return this.msg; + } +} diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/exception/RMException.java b/io/src/main/java/org/gcube/resourcemanagement/manager/exception/RMException.java new file mode 100644 index 0000000..466f9ad --- /dev/null +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/exception/RMException.java @@ -0,0 +1,29 @@ +package org.gcube.resourcemanagement.manager.exception; + +/** + * Exception returned by the Resource Manager. + * + * @author Manuele Simi (ISTI CNR) + * + */ +public class RMException extends Exception { + + private static final long serialVersionUID = 333945715086602250L; + + private final int errorCode; + private final String errorMsg; + + public RMException(ExceptionCode code) { + this.errorMsg = code.getMsg(); + this.errorCode = code.getId(); + } + + public int getErrorCode() { + return errorCode; + } + + public String getErrorMsg() { + return errorMsg; + } + +} diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/exception/package-info.java b/io/src/main/java/org/gcube/resourcemanagement/manager/exception/package-info.java new file mode 100644 index 0000000..6c9ff71 --- /dev/null +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/exception/package-info.java @@ -0,0 +1,6 @@ +/** + * Exception handling in the Resource Management. + * @author Manuele Simi (ISTI - CNR) + * + */ +package org.gcube.resourcemanagement.manager.exception; \ No newline at end of file diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/package-info.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/package-info.java deleted file mode 100644 index 9bd3412..0000000 --- a/io/src/main/java/org/gcube/resourcemanagement/manager/io/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @author Manuele Simi (ISTI - CNR) - * - */ -package org.gcube.resourcemanagement.manager.io; \ No newline at end of file