This commit is contained in:
六如
2024-11-04 00:13:28 +08:00
parent f76eab3c30
commit a598bf3404
2 changed files with 12 additions and 3 deletions

View File

@@ -22,6 +22,8 @@ public class ExceptionExecutorImpl implements ExceptionExecutor {
private static final String CONSTRAINT_VIOLATION_EXCEPTION = "ConstraintViolationException";
private static final String OPEN_EXCEPTION = "OpenException";
private static final String BIZ_ERROR_REGEX = "<OPEN_ERROR>(.*?)</OPEN_ERROR>";
static Pattern PATTERN = Pattern.compile(BIZ_ERROR_REGEX, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
@Override
public ApiResponse executeException(ApiRequestContext apiRequestContext, Exception e) {
@@ -36,7 +38,14 @@ public class ExceptionExecutorImpl implements ExceptionExecutor {
}
if (exceptionClass.contains(OPEN_EXCEPTION)) {
String exceptionMessage = genericException.getExceptionMessage();
String errorMsg = exceptionMessage.split("\n")[1];
Matcher matcher = PATTERN.matcher(exceptionMessage);
String errorMsg;
if (matcher.find()) {
errorMsg = matcher.group(1);
} else {
errorMsg = "biz-error@@系统错误";
}
// isv.common-error@@系统错误@@
String[] msgAr = errorMsg.split("@@");
return ApiResponse.error(
@@ -53,7 +62,7 @@ public class ExceptionExecutorImpl implements ExceptionExecutor {
}
private static Set<String> findErrorMsg(String text) {
Pattern pattern = Pattern.compile("'([^']*)'");
Pattern pattern = java.util.regex.Pattern.compile("'([^']*)'");
Matcher matcher = pattern.matcher(text);
Set<String> msgList = new LinkedHashSet<>();
while (matcher.find()) {

View File

@@ -35,6 +35,6 @@ public class OpenException extends RuntimeException {
@Override
public String toString() {
return String.join("@@", subCode, subMsg, solution);
return "<OPEN_ERROR>" + String.join("@@", subCode, subMsg, solution) + "</OPEN_ERROR>";
}
}