Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
customer-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QG
customer-service
Commits
b562e3e4
Commit
b562e3e4
authored
Apr 20, 2020
by
杨钧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加自定义异常处理
parent
e0c8aec6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
3 deletions
+47
-3
ValidOperatePermitFilter.java
...omer/config/http/mvc/filter/ValidOperatePermitFilter.java
+4
-2
ErrorCodeEnum.java
...main/java/cn/quantgroup/customer/enums/ErrorCodeEnum.java
+3
-1
ValidTokenException.java
...cn/quantgroup/customer/exception/ValidTokenException.java
+30
-0
AdviceRest.java
src/main/java/cn/quantgroup/customer/rest/AdviceRest.java
+10
-0
No files found.
src/main/java/cn/quantgroup/customer/config/http/mvc/filter/ValidOperatePermitFilter.java
View file @
b562e3e4
...
...
@@ -2,7 +2,9 @@ package cn.quantgroup.customer.config.http.mvc.filter;
import
cn.quantgroup.customer.config.container.UserThreadLocal
;
import
cn.quantgroup.customer.entity.OpUser
;
import
cn.quantgroup.customer.enums.ErrorCodeEnum
;
import
cn.quantgroup.customer.exception.BusinessException
;
import
cn.quantgroup.customer.exception.ValidTokenException
;
import
cn.quantgroup.customer.rest.vo.JsonResult
;
import
cn.quantgroup.customer.service.IOpSystemService
;
import
lombok.SneakyThrows
;
...
...
@@ -51,13 +53,13 @@ public class ValidOperatePermitFilter implements Filter {
String
system
=
request
.
getHeader
(
"x-auth-system"
);
if
(
StringUtils
.
isAnyBlank
(
token
,
system
))
{
log
.
error
(
"缺少token信息,拦截"
);
throw
new
BusinessException
(
"缺少token信息,拦截请求"
);
throw
new
ValidTokenException
(
ErrorCodeEnum
.
NO_TOKEN
);
}
JsonResult
<
OpUser
>
opUserResult
=
IOpSystemService
.
findUserByToken
(
token
,
system
);
if
(
Objects
.
isNull
(
opUserResult
)
||
!
opUserResult
.
isSuccess
())
{
log
.
error
(
"根据token查询不到用户信息 token:{}"
,
token
);
throw
new
BusinessException
(
"鉴权失败,拦截请求"
);
throw
new
ValidTokenException
(
ErrorCodeEnum
.
ILLEGAL_TOKEN
);
}
else
{
OpUser
opUser
=
opUserResult
.
getData
();
UserThreadLocal
.
set
(
opUser
);
...
...
src/main/java/cn/quantgroup/customer/enums/ErrorCodeEnum.java
View file @
b562e3e4
...
...
@@ -5,7 +5,9 @@ public enum ErrorCodeEnum {
NET_ERROR
(
6001L
,
"网络通讯异常"
),
RETURN_ERROR
(
7001L
,
"返回值异常"
),
PARAM_ERROR
(
7002L
,
"参数异常"
);
PARAM_ERROR
(
7002L
,
"参数异常"
),
NO_TOKEN
(
8001L
,
"缺少token信息"
),
ILLEGAL_TOKEN
(
8002L
,
"token信息有误"
);
public
String
getMessage
()
{
...
...
src/main/java/cn/quantgroup/customer/exception/ValidTokenException.java
0 → 100644
View file @
b562e3e4
package
cn
.
quantgroup
.
customer
.
exception
;
import
cn.quantgroup.customer.enums.ErrorCodeEnum
;
import
lombok.Getter
;
/**
* @author Jony
* @Date 2020/4/20 15:07
* @Desc
* @Update
*/
@Getter
public
class
ValidTokenException
extends
RuntimeException
{
private
Long
code
;
private
String
message
;
public
ValidTokenException
()
{
}
public
ValidTokenException
(
String
message
,
Long
code
)
{
super
(
message
);
this
.
code
=
code
;
}
public
ValidTokenException
(
ErrorCodeEnum
errorCodeEnum
)
{
this
.
code
=
errorCodeEnum
.
getCode
();
this
.
message
=
errorCodeEnum
.
getMessage
();
}
}
src/main/java/cn/quantgroup/customer/rest/AdviceRest.java
View file @
b562e3e4
...
...
@@ -2,6 +2,7 @@ package cn.quantgroup.customer.rest;
import
cn.quantgroup.customer.constant.Constant
;
import
cn.quantgroup.customer.exception.BusinessException
;
import
cn.quantgroup.customer.exception.ValidTokenException
;
import
cn.quantgroup.customer.rest.vo.JsonResult
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -31,4 +32,13 @@ public class AdviceRest {
}
@ExceptionHandler
({
ValidTokenException
.
class
})
@ResponseBody
@ResponseStatus
(
HttpStatus
.
OK
)
public
JsonResult
handleTokenException
(
ValidTokenException
ex
)
{
log
.
info
(
ex
.
getMessage
());
return
JsonResult
.
buildErrorStateResult
(
ex
.
getMessage
(),
ex
.
getCode
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment