mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-11-05 08:57:12 +08:00
新增:新增系统监控模块(存放系统监控模块相关功能,例如:日志管理、服务监控等),新增操作日志引擎,记录 HTTP 请求信息
This commit is contained in:
@@ -38,9 +38,12 @@ import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.exception.BadRequestException;
|
||||
import top.charles7c.cnadmin.common.exception.ServiceException;
|
||||
import top.charles7c.cnadmin.common.model.dto.OperationLog;
|
||||
import top.charles7c.cnadmin.common.model.vo.R;
|
||||
import top.charles7c.cnadmin.common.util.ExceptionUtils;
|
||||
import top.charles7c.cnadmin.common.util.StreamUtils;
|
||||
import top.charles7c.cnadmin.common.util.holder.LogContextHolder;
|
||||
|
||||
/**
|
||||
* 全局异常处理器
|
||||
@@ -58,6 +61,7 @@ public class GlobalExceptionHandler {
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(Exception.class)
|
||||
public R handleException(Exception e, HttpServletRequest request) {
|
||||
this.setException(e);
|
||||
log.error("请求地址'{}',发生未知异常", request.getRequestURI(), e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
@@ -68,10 +72,22 @@ public class GlobalExceptionHandler {
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public R handleRuntimeException(RuntimeException e, HttpServletRequest request) {
|
||||
this.setException(e);
|
||||
log.error("请求地址'{}',发生系统异常", request.getRequestURI(), e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截业务异常
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(ServiceException.class)
|
||||
public R handleServiceException(ServiceException e, HttpServletRequest request) {
|
||||
this.setException(e);
|
||||
log.error("请求地址'{}',发生业务异常", request.getRequestURI(), e);
|
||||
return R.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截自定义验证异常-错误请求
|
||||
*/
|
||||
@@ -147,4 +163,17 @@ public class GlobalExceptionHandler {
|
||||
log.error("请求地址'{}',认证失败'{}',无法访问系统资源", request.getRequestURI(), e.getMessage());
|
||||
return R.fail(HttpStatus.UNAUTHORIZED.value(), "认证失败,无法访问系统资源");
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作日志保存异常信息
|
||||
*
|
||||
* @param e
|
||||
* 异常信息
|
||||
*/
|
||||
private void setException(Exception e) {
|
||||
OperationLog operationLog = LogContextHolder.get();
|
||||
if (operationLog != null) {
|
||||
operationLog.setException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user