budaidev commented on code in PR #4756:
URL: https://github.com/apache/fineract/pull/4756#discussion_r2141995694


##########
fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java:
##########
@@ -132,41 +137,76 @@ public CommandProcessingResult executeCommand(final 
CommandWrapper wrapper, fina
 
             setIdempotencyKeyStoreFlag(true);
 
-            final CommandProcessingResult result;
+            return executeCommand(wrapper, command, isApprovedByChecker, 
commandSource, user, isEnclosingTransaction);
+        });
+    }
+
+    private CommandProcessingResult executeCommand(final CommandWrapper 
wrapper, final JsonCommand command,
+            final boolean isApprovedByChecker, CommandSource commandSource, 
AppUser user, boolean isEnclosingTransaction) {
+
+        final CommandProcessingResult result;
+        try {
+            result = 
commandSourceService.processCommand(findCommandHandler(wrapper), command, 
commandSource, user, isApprovedByChecker);
+        } catch (Throwable t) { // NOSONAR
+            RuntimeException mappable = ErrorHandler.getMappable(t);
+            ErrorInfo errorInfo = 
commandSourceService.generateErrorInfo(mappable);
+            Integer statusCode = errorInfo.getStatusCode();
+            commandSource.setResultStatusCode(statusCode);
+            commandSource.setResult(errorInfo.getMessage());
+            if (statusCode != SC_OK) {
+                commandSource.setStatus(ERROR);
+            }
+            if (!isEnclosingTransaction) { // TODO: temporary solution
+                commandSource = 
commandSourceService.saveResultNewTransaction(commandSource);
+            }
+            // must not throw any exception; must persist in new transaction 
as the current transaction was already
+            // marked as rollback
+            publishHookErrorEvent(wrapper, command, errorInfo);
+            throw mappable;
+        }
+
+        // Try to save the result with maximum retry attempts
+        boolean saveSuccess = false;
+        int maxRetries = 3; // Maximum number of retry attempts
+        RuntimeException lastException = null;
+
+        for (int retryCount = 0; retryCount < maxRetries && !saveSuccess; 
retryCount++) {

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to