Instead of creating separate classes for each exception type, create just one. Use enums to indicate the exception’s type. This reduces the class count and remove the need to declare ad-hoc exceptions.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@161800 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4b98621cc8
commit
57d6749dea
|
@ -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();
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Exception handling in the Resource Management.
|
||||
* @author Manuele Simi (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
package org.gcube.resourcemanagement.manager.exception;
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* @author Manuele Simi (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
package org.gcube.resourcemanagement.manager.io;
|
Reference in New Issue