Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
查尔斯-BUG万象集
Continew Admin
提交
90e1c64d
Continew Admin
项目概览
查尔斯-BUG万象集
/
Continew Admin
9 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
分析
仓库
DevOps
项目成员
Pages
Continew Admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
90e1c64d
编写于
8月 15, 2023
作者:
查尔斯-BUG万象集
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: 将全局异常处理器未知异常的异常类型从 Exception 调整为 Throwable
上级
487fa823
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
57 addition
and
57 deletion
+57
-57
continew-admin-common/src/main/java/top/charles7c/cnadmin/common/handler/GlobalExceptionHandler.java
...rles7c/cnadmin/common/handler/GlobalExceptionHandler.java
+52
-52
continew-admin-common/src/main/java/top/charles7c/cnadmin/common/model/dto/LogContext.java
...va/top/charles7c/cnadmin/common/model/dto/LogContext.java
+1
-1
continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/holder/LogContextHolder.java
...harles7c/cnadmin/common/util/holder/LogContextHolder.java
+3
-3
continew-admin-monitor/src/main/java/top/charles7c/cnadmin/monitor/interceptor/LogInterceptor.java
...charles7c/cnadmin/monitor/interceptor/LogInterceptor.java
+1
-1
未找到文件。
continew-admin-common/src/main/java/top/charles7c/cnadmin/common/handler/GlobalExceptionHandler.java
浏览文件 @
90e1c64d
...
...
@@ -59,39 +59,6 @@ import top.charles7c.cnadmin.common.util.holder.LogContextHolder;
@RestControllerAdvice
public
class
GlobalExceptionHandler
{
/**
* 拦截未知的系统异常
*/
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ExceptionHandler
(
Exception
.
class
)
public
R
handleException
(
Exception
e
,
HttpServletRequest
request
)
{
log
.
error
(
"请求地址 [{}],发生未知异常。"
,
request
.
getRequestURI
(),
e
);
LogContextHolder
.
setException
(
e
);
return
R
.
fail
(
e
.
getMessage
());
}
/**
* 拦截未知的运行时异常
*/
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ExceptionHandler
(
RuntimeException
.
class
)
public
R
handleRuntimeException
(
RuntimeException
e
,
HttpServletRequest
request
)
{
log
.
error
(
"请求地址 [{}],发生系统异常。"
,
request
.
getRequestURI
(),
e
);
LogContextHolder
.
setException
(
e
);
return
R
.
fail
(
e
.
getMessage
());
}
/**
* 拦截业务异常
*/
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ExceptionHandler
(
ServiceException
.
class
)
public
R
handleServiceException
(
ServiceException
e
,
HttpServletRequest
request
)
{
log
.
error
(
"请求地址 [{}],发生业务异常。"
,
request
.
getRequestURI
(),
e
);
LogContextHolder
.
setErrorMsg
(
e
.
getMessage
());
return
R
.
fail
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
(),
e
.
getMessage
());
}
/**
* 拦截自定义验证异常-错误请求
*/
...
...
@@ -104,25 +71,25 @@ public class GlobalExceptionHandler {
}
/**
* 拦截校验异常-
绑定
异常
* 拦截校验异常-
违反约束
异常
*/
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ExceptionHandler
(
Bind
Exception
.
class
)
public
R
handleBindException
(
Bind
Exception
e
,
HttpServletRequest
request
)
{
@ExceptionHandler
(
ConstraintViolation
Exception
.
class
)
public
R
constraintViolationException
(
ConstraintViolation
Exception
e
,
HttpServletRequest
request
)
{
log
.
warn
(
"请求地址 [{}],参数验证失败。"
,
request
.
getRequestURI
(),
e
);
String
errorMsg
=
StreamUtils
.
join
(
e
.
get
AllErrors
(),
DefaultMessageSourceResolvable:
:
getDefaul
tMessage
,
","
);
String
errorMsg
=
StreamUtils
.
join
(
e
.
get
ConstraintViolations
(),
ConstraintViolation:
:
ge
tMessage
,
","
);
LogContextHolder
.
setErrorMsg
(
errorMsg
);
return
R
.
fail
(
HttpStatus
.
BAD_REQUEST
.
value
(),
errorMsg
);
}
/**
* 拦截校验异常-
违反约束
异常
* 拦截校验异常-
绑定
异常
*/
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ExceptionHandler
(
ConstraintViolation
Exception
.
class
)
public
R
constraintViolationException
(
ConstraintViolation
Exception
e
,
HttpServletRequest
request
)
{
@ExceptionHandler
(
Bind
Exception
.
class
)
public
R
handleBindException
(
Bind
Exception
e
,
HttpServletRequest
request
)
{
log
.
warn
(
"请求地址 [{}],参数验证失败。"
,
request
.
getRequestURI
(),
e
);
String
errorMsg
=
StreamUtils
.
join
(
e
.
get
ConstraintViolations
(),
ConstraintViolation:
:
ge
tMessage
,
","
);
String
errorMsg
=
StreamUtils
.
join
(
e
.
get
AllErrors
(),
DefaultMessageSourceResolvable:
:
getDefaul
tMessage
,
","
);
LogContextHolder
.
setErrorMsg
(
errorMsg
);
return
R
.
fail
(
HttpStatus
.
BAD_REQUEST
.
value
(),
errorMsg
);
}
...
...
@@ -153,17 +120,6 @@ public class GlobalExceptionHandler {
return
R
.
fail
(
HttpStatus
.
BAD_REQUEST
.
value
(),
errorMsg
);
}
/**
* 拦截校验异常-请求方式不支持异常
*/
@ResponseStatus
(
HttpStatus
.
METHOD_NOT_ALLOWED
)
@ExceptionHandler
(
HttpRequestMethodNotSupportedException
.
class
)
public
R
handleHttpRequestMethodNotSupported
(
HttpRequestMethodNotSupportedException
e
,
HttpServletRequest
request
)
{
LogContextHolder
.
setErrorMsg
(
e
.
getMessage
());
log
.
error
(
"请求地址 [{}],不支持 [{}] 请求"
,
request
.
getRequestURI
(),
e
.
getMethod
());
return
R
.
fail
(
HttpStatus
.
METHOD_NOT_ALLOWED
.
value
(),
e
.
getMessage
());
}
/**
* 拦截文件上传异常-超过上传大小限制
*/
...
...
@@ -219,4 +175,48 @@ public class GlobalExceptionHandler {
log
.
error
(
"请求地址 [{}],角色权限校验失败。"
,
request
.
getRequestURI
(),
e
);
return
R
.
fail
(
HttpStatus
.
FORBIDDEN
.
value
(),
"没有访问权限,请联系管理员授权"
);
}
/**
* 拦截校验异常-请求方式不支持异常
*/
@ResponseStatus
(
HttpStatus
.
METHOD_NOT_ALLOWED
)
@ExceptionHandler
(
HttpRequestMethodNotSupportedException
.
class
)
public
R
handleHttpRequestMethodNotSupported
(
HttpRequestMethodNotSupportedException
e
,
HttpServletRequest
request
)
{
LogContextHolder
.
setErrorMsg
(
e
.
getMessage
());
log
.
error
(
"请求地址 [{}],不支持 [{}] 请求"
,
request
.
getRequestURI
(),
e
.
getMethod
());
return
R
.
fail
(
HttpStatus
.
METHOD_NOT_ALLOWED
.
value
(),
e
.
getMessage
());
}
/**
* 拦截业务异常
*/
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ExceptionHandler
(
ServiceException
.
class
)
public
R
handleServiceException
(
ServiceException
e
,
HttpServletRequest
request
)
{
log
.
error
(
"请求地址 [{}],发生业务异常。"
,
request
.
getRequestURI
(),
e
);
LogContextHolder
.
setErrorMsg
(
e
.
getMessage
());
return
R
.
fail
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
(),
e
.
getMessage
());
}
/**
* 拦截未知的运行时异常
*/
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ExceptionHandler
(
RuntimeException
.
class
)
public
R
handleRuntimeException
(
RuntimeException
e
,
HttpServletRequest
request
)
{
log
.
error
(
"请求地址 [{}],发生系统异常。"
,
request
.
getRequestURI
(),
e
);
LogContextHolder
.
setException
(
e
);
return
R
.
fail
(
e
.
getMessage
());
}
/**
* 拦截未知的系统异常
*/
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ExceptionHandler
(
Throwable
.
class
)
public
R
handleException
(
Throwable
e
,
HttpServletRequest
request
)
{
log
.
error
(
"请求地址 [{}],发生未知异常。"
,
request
.
getRequestURI
(),
e
);
LogContextHolder
.
setException
(
e
);
return
R
.
fail
(
e
.
getMessage
());
}
}
\ No newline at end of file
continew-admin-common/src/main/java/top/charles7c/cnadmin/common/model/dto/LogContext.java
浏览文件 @
90e1c64d
...
...
@@ -50,5 +50,5 @@ public class LogContext implements Serializable {
/**
* 异常信息
*/
private
Exception
exception
;
private
Throwable
exception
;
}
continew-admin-common/src/main/java/top/charles7c/cnadmin/common/util/holder/LogContextHolder.java
浏览文件 @
90e1c64d
...
...
@@ -64,9 +64,9 @@ public class LogContextHolder {
* @param e
* 异常信息
*/
public
static
void
setException
(
Exception
e
)
{
public
static
void
setException
(
Throwable
e
)
{
LogContext
logContext
=
get
();
if
(
logContext
!=
null
)
{
if
(
null
!=
logContext
)
{
logContext
.
setErrorMsg
(
e
.
getMessage
());
logContext
.
setException
(
e
);
}
...
...
@@ -80,7 +80,7 @@ public class LogContextHolder {
*/
public
static
void
setErrorMsg
(
String
errorMsg
)
{
LogContext
logContext
=
get
();
if
(
logContext
!=
null
)
{
if
(
null
!=
logContext
)
{
logContext
.
setErrorMsg
(
errorMsg
);
}
}
...
...
continew-admin-monitor/src/main/java/top/charles7c/cnadmin/monitor/interceptor/LogInterceptor.java
浏览文件 @
90e1c64d
...
...
@@ -141,7 +141,7 @@ public class LogInterceptor implements HandlerInterceptor {
logDO
.
setErrorMsg
(
errorMsg
);
}
// 记录异常详情
Exception
exception
=
logContext
.
getException
();
Throwable
exception
=
logContext
.
getException
();
if
(
null
!=
exception
)
{
logDO
.
setStatus
(
LogStatusEnum
.
FAILURE
);
logDO
.
setExceptionDetail
(
ExceptionUtil
.
stacktraceToString
(
exception
,
-
1
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录