|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package org.dromara.common.mybatis.handler;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpStatus;
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
|
|
@ -25,7 +26,7 @@ public class MybatisExceptionHandler {
|
|
|
|
|
public R<Void> handleDuplicateKeyException(DuplicateKeyException e, HttpServletRequest request) {
|
|
|
|
|
String requestURI = request.getRequestURI();
|
|
|
|
|
log.error("请求地址'{}',数据库中已存在记录'{}'", requestURI, e.getMessage());
|
|
|
|
|
return R.fail("数据库中已存在该记录,请联系管理员确认");
|
|
|
|
|
return R.fail(HttpStatus.HTTP_CONFLICT, "数据库中已存在该记录,请联系管理员确认");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -35,12 +36,12 @@ public class MybatisExceptionHandler {
|
|
|
|
|
public R<Void> handleCannotFindDataSourceException(MyBatisSystemException e, HttpServletRequest request) {
|
|
|
|
|
String requestURI = request.getRequestURI();
|
|
|
|
|
String message = e.getMessage();
|
|
|
|
|
if (StringUtils.contains("CannotFindDataSourceException", message)) {
|
|
|
|
|
if (StringUtils.contains(message, "CannotFindDataSourceException")) {
|
|
|
|
|
log.error("请求地址'{}', 未找到数据源", requestURI);
|
|
|
|
|
return R.fail("未找到数据源,请联系管理员确认");
|
|
|
|
|
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, "未找到数据源,请联系管理员确认");
|
|
|
|
|
}
|
|
|
|
|
log.error("请求地址'{}', Mybatis系统异常", requestURI, e);
|
|
|
|
|
return R.fail(message);
|
|
|
|
|
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|