SUPPORT-8897: Fix

This commit is contained in:
Eduard Tihomirov 2025-02-06 09:42:15 +03:00
parent 7b180ad6b6
commit ad9c1ef68f
5 changed files with 103 additions and 0 deletions

View file

@ -0,0 +1,61 @@
package ru.micord.ervu.error_handling;
import java.util.Arrays;
import org.springframework.context.annotation.Primary;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import ru.cg.webbpm.modules.core.app_info.api.mode.AppMode;
import ru.cg.webbpm.modules.core.error_handling.api.ProcessedWebException;
import ru.cg.webbpm.modules.core.error_handling.api.impl.UnknownExceptionHandler;
import ru.cg.webbpm.modules.core.runtime.api.MessageBundleUtils;
@Component
@Primary
public class ErvuUnknownExceptionHandler extends UnknownExceptionHandler {
protected static final MessageSourceAccessor ERVU_MESSAGE_SOURCE = MessageBundleUtils.createAccessor("exception_handler_messages");
@Override
public ProcessedWebException process(Throwable throwable) {
if (AppMode.mode() == AppMode.Mode.PROD) {
return new ProcessedWebException()
.addMessage(unknownErrorMessage());
}
else {
Throwable lastThrowable = findLastCause(throwable);
String lastThrowableStackTrace = Arrays.toString(lastThrowable.getStackTrace());
String limitLastThrowableStackTrace = lastThrowableStackTrace.length() > MAX_STACK_TRACE_LENGTH
? lastThrowableStackTrace.substring(0, MAX_STACK_TRACE_LENGTH) + " ..."
: lastThrowableStackTrace;
return new ProcessedWebException()
.addMessage(findLastNotEmptyMessage(throwable))
.setCauseStackTrace(limitLastThrowableStackTrace);
}
}
private String unknownErrorMessage() {
return ERVU_MESSAGE_SOURCE.getMessage("ervu.error.unknown", new Object[] {});
}
private Throwable findLastCause(Throwable throwable) {
if (throwable.getCause() != null) {
return findLastCause(throwable.getCause());
}
return throwable;
}
private String findLastNotEmptyMessage(Throwable throwable) {
String message = throwable.getMessage();
if(throwable.getCause() != null) {
String nextMessage = findLastNotEmptyMessage(throwable.getCause());
if(!StringUtils.isEmpty(nextMessage)) {
message = nextMessage;
}
}
return message;
}
}

View file

@ -0,0 +1 @@
ervu.error.unknown=??????? ???????? ??????????. ??????????, ????????? ??????? ?????.

View file

@ -0,0 +1 @@
ervu.error.unknown=The system is temporarily unavailable. Please try again later.