From 9a8a4a431c61d22a334003b2e8a52571ea809920 Mon Sep 17 00:00:00 2001
From: heheng <475597332@qq.com>
Date: Mon, 24 Mar 2025 13:15:34 +0800
Subject: [PATCH] 增加业务类别
---
assess-framework/src/main/java/com/gkhy/assess/framework/exception/GlobalExceptionHandler.java | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/assess-framework/src/main/java/com/gkhy/assess/framework/exception/GlobalExceptionHandler.java b/assess-framework/src/main/java/com/gkhy/assess/framework/exception/GlobalExceptionHandler.java
index d4b5872..a92ec25 100644
--- a/assess-framework/src/main/java/com/gkhy/assess/framework/exception/GlobalExceptionHandler.java
+++ b/assess-framework/src/main/java/com/gkhy/assess/framework/exception/GlobalExceptionHandler.java
@@ -4,6 +4,7 @@
import com.gkhy.assess.common.exception.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.authz.UnauthorizedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -18,6 +19,7 @@
import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
+import java.sql.SQLSyntaxErrorException;
/**
* 全局异常处理类
@@ -30,7 +32,7 @@
@ExceptionHandler(value = ApiException.class)
public CommonResult handle(ApiException e){
- writeExceptionLogFile(e);
+ // writeExceptionLogFile(e);
if(e.getErrorCode()!=null){
return CommonResult.failed(e.getErrorCode());
}
@@ -78,11 +80,21 @@
/**
* 拦截未知的运行时异常
*/
+ @ExceptionHandler(UnauthorizedException.class)
+ public CommonResult handleUnauthorizedException(RuntimeException ex, HttpServletRequest request)
+ {
+ writeExceptionLogFile(ex);
+ return CommonResult.failed("权限不足,无权操作!");
+ }
+
+ /**
+ * 拦截未知的运行时异常
+ */
@ExceptionHandler(RuntimeException.class)
public CommonResult handleRuntimeException(RuntimeException ex, HttpServletRequest request)
{
writeExceptionLogFile(ex);
- return CommonResult.failed(ex.getMessage());
+ return CommonResult.failed("内部服务异常");
}
@@ -104,7 +116,7 @@
if (request!=null) {
url=request.getRequestURI();
}
- log.error("error={}",ex);
+ log.error("error:",ex);
log.error(ex.getMessage()+",url={}",url);
}
}
--
Gitblit v1.9.2