mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-27 05:36:41 +08:00
fix 修复 mybatis内报token异常无法正常返回前端信息
This commit is contained in:
parent
4f15158486
commit
8905e232e5
@ -5,7 +5,9 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.core.domain.R;
|
import org.dromara.common.core.domain.R;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
|
import org.dromara.common.satoken.handler.SaTokenExceptionHandler;
|
||||||
import org.mybatis.spring.MyBatisSystemException;
|
import org.mybatis.spring.MyBatisSystemException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
@ -19,6 +21,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class MybatisExceptionHandler {
|
public class MybatisExceptionHandler {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SaTokenExceptionHandler saTokenExceptionHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主键或UNIQUE索引,数据重复异常
|
* 主键或UNIQUE索引,数据重复异常
|
||||||
*/
|
*/
|
||||||
@ -40,6 +45,10 @@ public class MybatisExceptionHandler {
|
|||||||
log.error("请求地址'{}', 未找到数据源", requestURI);
|
log.error("请求地址'{}', 未找到数据源", requestURI);
|
||||||
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, "未找到数据源,请联系管理员确认");
|
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, "未找到数据源,请联系管理员确认");
|
||||||
}
|
}
|
||||||
|
if (StringUtils.contains(message, "NotLoginException")) {
|
||||||
|
log.error("请求地址'{}',认证失败'{}',无法访问系统资源", requestURI, e.getMessage());
|
||||||
|
return R.fail(HttpStatus.HTTP_UNAUTHORIZED, "认证失败,无法访问系统资源");
|
||||||
|
}
|
||||||
log.error("请求地址'{}', Mybatis系统异常", requestURI, e);
|
log.error("请求地址'{}', Mybatis系统异常", requestURI, e);
|
||||||
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, message);
|
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, message);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user