use AbstractPlatformException as superclass for various exceptions
related to FINERACT-942 and as per code review discussion in PR #1079.
This commit is contained in:
committed by
Michael Vorburger ⛑️
parent
7a88f14eec
commit
56cad56848
+5
-23
@@ -19,30 +19,12 @@
|
||||
package org.apache.fineract.infrastructure.core.exception;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when valid api request end up violating some domain rule.
|
||||
* A {@link RuntimeException} thrown when a valid API request ends up violating some domain rule.
|
||||
*/
|
||||
public abstract class AbstractPlatformDomainRuleException extends RuntimeException {
|
||||
public abstract class AbstractPlatformDomainRuleException extends AbstractPlatformException {
|
||||
|
||||
private final String globalisationMessageCode;
|
||||
private final String defaultUserMessage;
|
||||
private final Object[] defaultUserMessageArgs;
|
||||
|
||||
protected AbstractPlatformDomainRuleException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||
final Object... defaultUserMessageArgs) {
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
this.defaultUserMessageArgs = defaultUserMessageArgs;
|
||||
}
|
||||
|
||||
public String getGlobalisationMessageCode() {
|
||||
return this.globalisationMessageCode;
|
||||
}
|
||||
|
||||
public String getDefaultUserMessage() {
|
||||
return this.defaultUserMessage;
|
||||
}
|
||||
|
||||
public Object[] getDefaultUserMessageArgs() {
|
||||
return this.defaultUserMessageArgs;
|
||||
protected AbstractPlatformDomainRuleException(String globalisationMessageCode, String defaultUserMessage,
|
||||
Object... defaultUserMessageArgs) {
|
||||
super(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs);
|
||||
}
|
||||
}
|
||||
|
||||
+43
-3
@@ -21,9 +21,38 @@ package org.apache.fineract.infrastructure.core.exception;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractPlatformException {
|
||||
/**
|
||||
* Exception with internationalization support (it's message can be translated).
|
||||
*/
|
||||
public abstract class AbstractPlatformException extends RuntimeException {
|
||||
|
||||
protected static Throwable findThrowableCause(Object[] defaultUserMessageArgs) {
|
||||
private static final Object[] NO_ARGS = new Object[0];
|
||||
|
||||
private final String globalisationMessageCode;
|
||||
private final String defaultUserMessage;
|
||||
private final Object[] defaultUserMessageArgs;
|
||||
|
||||
protected AbstractPlatformException(String globalisationMessageCode, String defaultUserMessage, Object[] defaultUserMessageArgs) {
|
||||
super(findThrowableCause(defaultUserMessageArgs));
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
this.defaultUserMessageArgs = AbstractPlatformException.filterThrowableCause(defaultUserMessageArgs);
|
||||
}
|
||||
|
||||
protected AbstractPlatformException(String globalisationMessageCode, String defaultUserMessage) {
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
this.defaultUserMessageArgs = NO_ARGS;
|
||||
}
|
||||
|
||||
protected AbstractPlatformException(String globalisationMessageCode, String defaultUserMessage, Throwable cause) {
|
||||
super(cause);
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
this.defaultUserMessageArgs = NO_ARGS;
|
||||
}
|
||||
|
||||
private static Throwable findThrowableCause(Object[] defaultUserMessageArgs) {
|
||||
for (Object defaultUserMessageArg : defaultUserMessageArgs) {
|
||||
if (defaultUserMessageArg instanceof Throwable) {
|
||||
return (Throwable) defaultUserMessageArg;
|
||||
@@ -32,7 +61,7 @@ public abstract class AbstractPlatformException {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static Object[] filterThrowableCause(Object[] defaultUserMessageArgs) {
|
||||
private static Object[] filterThrowableCause(Object[] defaultUserMessageArgs) {
|
||||
List<Object> filteredDefaultUserMessageArgs = new ArrayList<>(defaultUserMessageArgs.length);
|
||||
for (Object defaultUserMessageArg : defaultUserMessageArgs) {
|
||||
if (!(defaultUserMessageArg instanceof Throwable)) {
|
||||
@@ -42,4 +71,15 @@ public abstract class AbstractPlatformException {
|
||||
return filteredDefaultUserMessageArgs.toArray();
|
||||
}
|
||||
|
||||
public final String getGlobalisationMessageCode() {
|
||||
return this.globalisationMessageCode;
|
||||
}
|
||||
|
||||
public final String getDefaultUserMessage() {
|
||||
return this.defaultUserMessage;
|
||||
}
|
||||
|
||||
public final Object[] getDefaultUserMessageArgs() {
|
||||
return this.defaultUserMessageArgs;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-21
@@ -21,29 +21,10 @@ package org.apache.fineract.infrastructure.core.exception;
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when resources that are queried for are not found.
|
||||
*/
|
||||
public abstract class AbstractPlatformResourceNotFoundException extends RuntimeException {
|
||||
|
||||
private final String globalisationMessageCode;
|
||||
private final String defaultUserMessage;
|
||||
private final Object[] defaultUserMessageArgs;
|
||||
public abstract class AbstractPlatformResourceNotFoundException extends AbstractPlatformException {
|
||||
|
||||
protected AbstractPlatformResourceNotFoundException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||
final Object... defaultUserMessageArgs) {
|
||||
super(AbstractPlatformException.findThrowableCause(defaultUserMessageArgs));
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
this.defaultUserMessageArgs = AbstractPlatformException.filterThrowableCause(defaultUserMessageArgs);
|
||||
}
|
||||
|
||||
public String getGlobalisationMessageCode() {
|
||||
return this.globalisationMessageCode;
|
||||
}
|
||||
|
||||
public String getDefaultUserMessage() {
|
||||
return this.defaultUserMessage;
|
||||
}
|
||||
|
||||
public Object[] getDefaultUserMessageArgs() {
|
||||
return this.defaultUserMessageArgs;
|
||||
super(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-23
@@ -19,30 +19,12 @@
|
||||
package org.apache.fineract.infrastructure.core.exception;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when resources that are queried for are not found.
|
||||
* A {@link RuntimeException} thrown for cases such as 3rd-party external services that are not available.
|
||||
*/
|
||||
public abstract class AbstractPlatformServiceUnavailableException extends RuntimeException {
|
||||
public abstract class AbstractPlatformServiceUnavailableException extends AbstractPlatformException {
|
||||
|
||||
private final String globalisationMessageCode;
|
||||
private final String defaultUserMessage;
|
||||
private final Object[] defaultUserMessageArgs;
|
||||
|
||||
protected AbstractPlatformServiceUnavailableException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||
final Object... defaultUserMessageArgs) {
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
this.defaultUserMessageArgs = defaultUserMessageArgs;
|
||||
}
|
||||
|
||||
public String getGlobalisationMessageCode() {
|
||||
return this.globalisationMessageCode;
|
||||
}
|
||||
|
||||
public String getDefaultUserMessage() {
|
||||
return this.defaultUserMessage;
|
||||
}
|
||||
|
||||
public Object[] getDefaultUserMessageArgs() {
|
||||
return this.defaultUserMessageArgs;
|
||||
protected AbstractPlatformServiceUnavailableException(String globalisationMessageCode, String defaultUserMessage,
|
||||
Object... defaultUserMessageArgs) {
|
||||
super(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@ package org.apache.fineract.infrastructure.core.exception;
|
||||
*/
|
||||
public final class GeneralPlatformDomainRuleException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public GeneralPlatformDomainRuleException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||
final Object... defaultUserMessageArgs) {
|
||||
public GeneralPlatformDomainRuleException(String globalisationMessageCode, String defaultUserMessage,
|
||||
Object... defaultUserMessageArgs) {
|
||||
super(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -20,8 +20,6 @@ package org.apache.fineract.infrastructure.core.exception;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} that is thrown in the case where invalid JSON is sent in the body of the request to the
|
||||
* platform api.
|
||||
* platform API.
|
||||
*/
|
||||
public class InvalidJsonException extends RuntimeException {
|
||||
//
|
||||
}
|
||||
public class InvalidJsonException extends RuntimeException {}
|
||||
|
||||
+11
-28
@@ -24,46 +24,29 @@ import org.apache.fineract.infrastructure.core.data.ApiParameterError;
|
||||
/**
|
||||
* Exception thrown when problem with an API request to the platform.
|
||||
*/
|
||||
public class PlatformApiDataValidationException extends RuntimeException {
|
||||
public class PlatformApiDataValidationException extends AbstractPlatformException {
|
||||
|
||||
private final String globalisationMessageCode;
|
||||
private final String defaultUserMessage;
|
||||
private final List<ApiParameterError> errors;
|
||||
|
||||
public PlatformApiDataValidationException(final List<ApiParameterError> errors) {
|
||||
this.globalisationMessageCode = "validation.msg.validation.errors.exist";
|
||||
this.defaultUserMessage = "Validation errors exist.";
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public PlatformApiDataValidationException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||
final List<ApiParameterError> errors) {
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public PlatformApiDataValidationException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||
final List<ApiParameterError> errors, Throwable cause) {
|
||||
super(cause);
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
public PlatformApiDataValidationException(List<ApiParameterError> errors) {
|
||||
super("validation.msg.validation.errors.exist", "Validation errors exist.");
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public PlatformApiDataValidationException(final List<ApiParameterError> errors, Throwable cause) {
|
||||
super(cause);
|
||||
this.globalisationMessageCode = "validation.msg.validation.errors.exist";
|
||||
this.defaultUserMessage = "Validation errors exist.";
|
||||
super("validation.msg.validation.errors.exist", "Validation errors exist.", cause);
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public String getGlobalisationMessageCode() {
|
||||
return this.globalisationMessageCode;
|
||||
public PlatformApiDataValidationException(String globalisationMessageCode, String defaultUserMessage, List<ApiParameterError> errors) {
|
||||
super(globalisationMessageCode, defaultUserMessage);
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public String getDefaultUserMessage() {
|
||||
return this.defaultUserMessage;
|
||||
public PlatformApiDataValidationException(String globalisationMessageCode, String defaultUserMessage, List<ApiParameterError> errors,
|
||||
Throwable cause) {
|
||||
super(globalisationMessageCode, defaultUserMessage, cause);
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public List<ApiParameterError> getErrors() {
|
||||
|
||||
+3
-24
@@ -21,41 +21,20 @@ package org.apache.fineract.infrastructure.core.exception;
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when data integrity problems happen due to state modifying actions.
|
||||
*/
|
||||
public class PlatformDataIntegrityException extends RuntimeException {
|
||||
public class PlatformDataIntegrityException extends AbstractPlatformException {
|
||||
|
||||
private final String globalisationMessageCode;
|
||||
private final String defaultUserMessage;
|
||||
private final String parameterName;
|
||||
private final Object[] defaultUserMessageArgs;
|
||||
|
||||
public PlatformDataIntegrityException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||
final Object... defaultUserMessageArgs) {
|
||||
super(AbstractPlatformException.findThrowableCause(defaultUserMessageArgs));
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
super(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs);
|
||||
this.parameterName = null;
|
||||
this.defaultUserMessageArgs = AbstractPlatformException.filterThrowableCause(defaultUserMessageArgs);
|
||||
}
|
||||
|
||||
public PlatformDataIntegrityException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||
final String parameterName, final Object... defaultUserMessageArgs) {
|
||||
super(AbstractPlatformException.findThrowableCause(defaultUserMessageArgs));
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
super(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs);
|
||||
this.parameterName = parameterName;
|
||||
this.defaultUserMessageArgs = AbstractPlatformException.filterThrowableCause(defaultUserMessageArgs);
|
||||
}
|
||||
|
||||
public String getGlobalisationMessageCode() {
|
||||
return this.globalisationMessageCode;
|
||||
}
|
||||
|
||||
public String getDefaultUserMessage() {
|
||||
return this.defaultUserMessage;
|
||||
}
|
||||
|
||||
public Object[] getDefaultUserMessageArgs() {
|
||||
return this.defaultUserMessageArgs;
|
||||
}
|
||||
|
||||
public String getParameterName() {
|
||||
|
||||
+3
-22
@@ -21,28 +21,9 @@ package org.apache.fineract.infrastructure.core.exception;
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when unexpected server side errors happen.
|
||||
*/
|
||||
public class PlatformInternalServerException extends RuntimeException {
|
||||
public class PlatformInternalServerException extends AbstractPlatformException {
|
||||
|
||||
private final String globalisationMessageCode;
|
||||
private final String defaultUserMessage;
|
||||
private final Object[] defaultUserMessageArgs;
|
||||
|
||||
public PlatformInternalServerException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||
final Object... defaultUserMessageArgs) {
|
||||
this.globalisationMessageCode = globalisationMessageCode;
|
||||
this.defaultUserMessage = defaultUserMessage;
|
||||
this.defaultUserMessageArgs = defaultUserMessageArgs;
|
||||
}
|
||||
|
||||
public String getGlobalisationMessageCode() {
|
||||
return this.globalisationMessageCode;
|
||||
}
|
||||
|
||||
public String getDefaultUserMessage() {
|
||||
return this.defaultUserMessage;
|
||||
}
|
||||
|
||||
public Object[] getDefaultUserMessageArgs() {
|
||||
return this.defaultUserMessageArgs;
|
||||
public PlatformInternalServerException(String globalisationMessageCode, String defaultUserMessage, Object... defaultUserMessageArgs) {
|
||||
super(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs);
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+2
-3
@@ -20,9 +20,8 @@ package org.apache.fineract.infrastructure.core.exception;
|
||||
|
||||
public class PlatformServiceUnavailableException extends AbstractPlatformServiceUnavailableException {
|
||||
|
||||
public PlatformServiceUnavailableException(final String globalisationMessageCode, final String defaultUserMessage,
|
||||
final Object... defaultUserMessageArgs) {
|
||||
public PlatformServiceUnavailableException(String globalisationMessageCode, String defaultUserMessage,
|
||||
Object... defaultUserMessageArgs) {
|
||||
super(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user