optimize(ebom): 优化错误提示

This commit is contained in:
曹鹏飞 2024-06-20 15:32:11 +08:00
parent 5a78ef449a
commit 0e7cc1e877
1 changed files with 21 additions and 1 deletions

View File

@ -17,7 +17,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.NoHandlerFoundException;
import java.sql.BatchUpdateException;
import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
/**
* 异常处理器
@ -171,9 +173,27 @@ public class BaseGlobalExceptionHandle {
@ExceptionHandler(value = InvalidFormatException.class)
@ResponseBody
public ResultVO handleInvalidFormatException(ErrorMsgException e) {
public ResultVO handleInvalidFormatException(InvalidFormatException e) {
log.error(e.getMessage(), e);
//return ResultVO.error(e.getState(), e.getMessage());
return ResultVO.error(STATE.ParamErr, "数据格式错误,请修改后再提交: " + e.getMessage());
}
@ExceptionHandler(value = SQLSyntaxErrorException.class)
@ResponseBody
public ResultVO handleSQLSyntaxErrorException(SQLSyntaxErrorException e) {
log.error(e.getMessage(), e);
return ResultVO.error(STATE.ParamErr, "SQL语法错误");
}
@ExceptionHandler(value = BatchUpdateException.class)
@ResponseBody
public ResultVO handleSQLSyntaxErrorException(BatchUpdateException e) {
log.error(e.getMessage(), e);
if (StrUtil.isNotBlank(e.getMessage()) && e.getMessage().contains("Deadlock")) {
return ResultVO.error("操作失败,请重试");
} else {
return ResultVO.error("更新数据失败");
}
}
}