Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
7be21be8
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7be21be8
编写于
3月 05, 2024
作者:
H
hxr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 修复未知异常被 `token` 无效处理器拦截报错token无效的错误
上级
fcf0c3fd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
9 addition
and
16 deletion
+9
-16
youlai-common/common-security/src/main/java/com/youlai/common/security/exception/MyAuthenticationEntryPoint.java
...common/security/exception/MyAuthenticationEntryPoint.java
+3
-11
youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java
...m/youlai/common/web/exception/GlobalExceptionHandler.java
+6
-5
未找到文件。
youlai-common/common-security/src/main/java/com/youlai/common/security/exception/MyAuthenticationEntryPoint.java
浏览文件 @
7be21be8
...
...
@@ -15,7 +15,7 @@ import java.io.IOException;
* 自定义 token 无效异常
*
* @author haoxr
* @
dat
e 2022/11/13
* @
sinc
e 2022/11/13
*/
@Component
public
class
MyAuthenticationEntryPoint
implements
AuthenticationEntryPoint
{
...
...
@@ -23,16 +23,8 @@ public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
public
void
commence
(
HttpServletRequest
request
,
HttpServletResponse
response
,
AuthenticationException
authException
)
throws
IOException
{
response
.
setContentType
(
"application/json"
);
int
status
=
response
.
getStatus
();
ObjectMapper
mapper
=
new
ObjectMapper
();
if
(
HttpServletResponse
.
SC_NOT_FOUND
==
status
)
{
response
.
setStatus
(
HttpServletResponse
.
SC_NOT_FOUND
);
mapper
.
writeValue
(
response
.
getOutputStream
(),
Result
.
failed
(
ResultCode
.
RESOURCE_NOT_FOUND
));
}
else
{
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
mapper
.
writeValue
(
response
.
getOutputStream
(),
Result
.
failed
(
ResultCode
.
TOKEN_INVALID
));
}
response
.
setStatus
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
mapper
.
writeValue
(
response
.
getOutputStream
(),
Result
.
failed
(
ResultCode
.
TOKEN_INVALID
));
}
}
youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java
浏览文件 @
7be21be8
...
...
@@ -23,6 +23,7 @@ import org.springframework.web.servlet.NoHandlerFoundException;
import
jakarta.servlet.ServletException
;
import
jakarta.validation.ConstraintViolation
;
import
jakarta.validation.ConstraintViolationException
;
import
java.sql.SQLSyntaxErrorException
;
import
java.util.concurrent.CompletionException
;
import
java.util.regex.Matcher
;
...
...
@@ -201,15 +202,15 @@ public class GlobalExceptionHandler {
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ExceptionHandler
(
Exception
.
class
)
public
<
T
>
Result
<
T
>
handleException
(
Exception
e
)
{
e
.
printStackTrace
(
);
log
.
error
(
"unknown exception:{}"
,
e
.
getMessage
(),
e
);
String
errorMsg
=
e
.
getMessage
();
if
(
StrUtil
.
isNotBlank
(
errorMsg
)
&&
errorMsg
.
contains
(
"denied to user"
))
{
return
Result
.
failed
(
ResultCode
.
FORBIDDEN_OPERATION
);
}
else
{
log
.
error
(
"unknown exception"
);
errorMsg
=
e
.
getCause
().
getMessage
();
return
Result
.
failed
(
errorMsg
);
}
if
(
StrUtil
.
isBlank
(
errorMsg
))
{
errorMsg
=
"系统异常"
;
}
return
Result
.
failed
(
errorMsg
);
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录