🎨 统一异常处理增加 DataDuplicationException 支持

This commit is contained in:
ronger 2022-08-01 21:47:32 +08:00
parent 35cc83ec00
commit ff18724432
2 changed files with 10 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package com.rymcu.forest.config; package com.rymcu.forest.config;
import com.alibaba.fastjson.support.spring.FastJsonJsonView; import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.rymcu.forest.core.exception.DataDuplicationException;
import com.rymcu.forest.core.exception.ServiceException; import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.core.exception.TransactionException; import com.rymcu.forest.core.exception.TransactionException;
import com.rymcu.forest.core.result.GlobalResult; import com.rymcu.forest.core.result.GlobalResult;
@ -62,6 +63,9 @@ public class BaseExceptionHandler {
} else if (ex instanceof ServletException) { } else if (ex instanceof ServletException) {
result.setCode(ResultCode.FAIL.getCode()); result.setCode(ResultCode.FAIL.getCode());
result.setMessage(ex.getMessage()); result.setMessage(ex.getMessage());
} else if (ex instanceof DataDuplicationException) {
result.setCode(ResultCode.FAIL.getCode());
result.setMessage(ex.getMessage());
} else if (ex instanceof TransactionException) { } else if (ex instanceof TransactionException) {
result.setCode(TransactionCode.InsufficientBalance.getCode()); result.setCode(TransactionCode.InsufficientBalance.getCode());
result.setMessage(ex.getMessage()); result.setMessage(ex.getMessage());
@ -108,6 +112,9 @@ public class BaseExceptionHandler {
} else if (ex instanceof ServletException) { } else if (ex instanceof ServletException) {
attributes.put("code", ResultCode.FAIL.getCode()); attributes.put("code", ResultCode.FAIL.getCode());
attributes.put("message", ex.getMessage()); attributes.put("message", ex.getMessage());
} else if (ex instanceof DataDuplicationException) {
attributes.put("code", ResultCode.FAIL.getCode());
attributes.put("message", ex.getMessage());
} else if (ex instanceof TransactionException) { } else if (ex instanceof TransactionException) {
attributes.put("code", TransactionCode.InsufficientBalance.getCode()); attributes.put("code", TransactionCode.InsufficientBalance.getCode());
attributes.put("message", ex.getMessage()); attributes.put("message", ex.getMessage());

View File

@ -1,5 +1,8 @@
package com.rymcu.forest.core.exception; package com.rymcu.forest.core.exception;
/**
* @author KKould
*/
public class DataDuplicationException extends RuntimeException { public class DataDuplicationException extends RuntimeException {
private static final long serialVersionUID = 3206744387536223284L; private static final long serialVersionUID = 3206744387536223284L;