From 579177ac64462d0fec885eb10af3097245134f80 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Tue, 02 Jun 2026 10:28:11 +0800
Subject: [PATCH] 1
---
trading-order-common/src/main/java/com/yami/trading/common/config/DefaultExceptionHandlerConfig.java | 25 ++++++++++++++++++-------
1 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/trading-order-common/src/main/java/com/yami/trading/common/config/DefaultExceptionHandlerConfig.java b/trading-order-common/src/main/java/com/yami/trading/common/config/DefaultExceptionHandlerConfig.java
index 19f15d4..37ac981 100644
--- a/trading-order-common/src/main/java/com/yami/trading/common/config/DefaultExceptionHandlerConfig.java
+++ b/trading-order-common/src/main/java/com/yami/trading/common/config/DefaultExceptionHandlerConfig.java
@@ -13,6 +13,7 @@
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.BusinessException;
import com.yami.trading.common.exception.YamiShopBindException;
+import com.yami.trading.common.util.ApiMessageTranslator;
import com.yami.trading.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
@@ -44,7 +45,7 @@
@ExceptionHandler(MethodArgumentNotValidException.class)
- public Result <String> exception(MethodArgumentNotValidException e) {
+ public Result <String> exception(MethodArgumentNotValidException e, HttpServletRequest req) {
BindingResult bindingResult = e.getBindingResult();
List<ObjectError> allErrors = bindingResult.getAllErrors();
List<ErrorMsg> errorMsgs = new ArrayList<>();
@@ -56,7 +57,7 @@
errorMsg.setMessage(fieldError.getDefaultMessage());
errorMsgs.add(errorMsg);
});
- return Result.failed(errorMsgs.toString()); }
+ return Result.failed(translateForUserClient(req, errorMsgs.toString())); }
@ExceptionHandler(value = ConstraintViolationException.class)
@@ -89,7 +90,7 @@
log.error("{}", ex);
String message = ex.getMessage();
if(StringUtils.isNotEmpty(message)){
- return Result.failed(message);
+ return Result.failed(translateForUserClient(req, message));
}else{
return Result.failed(ex.toString());
}
@@ -98,13 +99,23 @@
@ExceptionHandler(YamiShopBindException.class)
- public Result unauthorizedExceptionHandler(YamiShopBindException e){
+ public Result unauthorizedExceptionHandler(YamiShopBindException e, HttpServletRequest req){
log.error("YamiException Message :{}",e.getMessage());
- return Result.of(null,e.getCode(),e.getMessage());
+ return Result.of(null,e.getCode(),translateForUserClient(req, e.getMessage()));
}
@ExceptionHandler(BusinessException.class)
- public Result businessExceptionHandler(BusinessException e){
+ public Result businessExceptionHandler(BusinessException e, HttpServletRequest req){
log.error("YamiException Message :{}",e.getMessage());
- return Result.failed(e.getMessage());
+ return Result.failed(translateForUserClient(req, e.getMessage()));
+ }
+
+ private static String translateForUserClient(HttpServletRequest req, String message) {
+ if (req == null || message == null) {
+ return message;
+ }
+ if (ApiMessageTranslator.isUserApiRequest(req.getRequestURI())) {
+ return ApiMessageTranslator.toEnglish(message);
+ }
+ return message;
}
}
--
Gitblit v1.9.3