FINERACT-2304: Making sure that in the publishHookErrorEvent or publishHookEvent does not throw any exception
This commit is contained in:
+12
-4
@@ -211,7 +211,11 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
}
|
||||
|
||||
private void publishHookErrorEvent(CommandWrapper wrapper, JsonCommand command, ErrorInfo errorInfo) {
|
||||
try {
|
||||
publishHookEvent(wrapper.entityName(), wrapper.actionName(), command, gson.toJson(errorInfo));
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to publish hook error event for entity: {}, action: {}", wrapper.entityName(), wrapper.actionName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void exceptionWhenTheRequestAlreadyProcessed(CommandWrapper wrapper, String idempotencyKey, boolean retry) {
|
||||
@@ -323,7 +327,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
}
|
||||
|
||||
protected void publishHookEvent(final String entityName, final String actionName, JsonCommand command, final Object result) {
|
||||
|
||||
try {
|
||||
final AppUser appUser = context.authenticatedUser(CommandWrapper.wrap(actionName, entityName, null, null));
|
||||
|
||||
final HookEventSource hookEventSource = new HookEventSource(entityName, actionName);
|
||||
@@ -339,8 +343,8 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
try {
|
||||
myMap = gson.fromJson(command.json(), type);
|
||||
} catch (Exception e) {
|
||||
throw new PlatformApiDataValidationException("error.msg.invalid.json", "The provided JSON is invalid.", new ArrayList<>(),
|
||||
e);
|
||||
throw new PlatformApiDataValidationException("error.msg.invalid.json", "The provided JSON is invalid.",
|
||||
new ArrayList<>(), e);
|
||||
}
|
||||
|
||||
Map<String, Object> reqmap = new HashMap<>();
|
||||
@@ -352,7 +356,8 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
|
||||
reqmap.put("request", myMap);
|
||||
if (result instanceof CommandProcessingResult) {
|
||||
CommandProcessingResult resultCopy = CommandProcessingResult.fromCommandProcessingResult((CommandProcessingResult) result);
|
||||
CommandProcessingResult resultCopy = CommandProcessingResult
|
||||
.fromCommandProcessingResult((CommandProcessingResult) result);
|
||||
|
||||
reqmap.put("officeId", resultCopy.getOfficeId());
|
||||
reqmap.put("clientId", resultCopy.getClientId());
|
||||
@@ -384,5 +389,8 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
|
||||
applicationContext.publishEvent(applicationEvent);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to publish hook event for entity: {}, action: {}", entityName, actionName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.fineract.commands.service;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -53,7 +54,6 @@ import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractRequestContextHolder;
|
||||
import org.apache.fineract.infrastructure.core.exception.IdempotentCommandProcessUnderProcessingException;
|
||||
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
@@ -473,7 +473,8 @@ public class SynchronousCommandProcessingServiceTest {
|
||||
|
||||
when(command.json()).thenReturn(invalidJson);
|
||||
|
||||
assertThrows(PlatformApiDataValidationException.class, () -> {
|
||||
// Test that no exception is thrown (exceptions are caught and logged)
|
||||
assertDoesNotThrow(() -> {
|
||||
underTest.publishHookEvent(entityName, actionName, command, Object.class);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user