Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-enterprise-base
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
base_platform_enterprise
gic-enterprise-base
Commits
c647aeb9
Commit
c647aeb9
authored
Sep 23, 2020
by
guojuxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
全局异常修改
parent
333d12a1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 additions
and
33 deletions
+1
-33
GlobalExceptionHandler.java
.../com/gic/enterprise/exception/GlobalExceptionHandler.java
+1
-25
AuthInterceptor.java
.../java/com/gic/enterprise/interceptor/AuthInterceptor.java
+0
-8
No files found.
gic-enterprise-common/src/main/java/com/gic/enterprise/exception/GlobalExceptionHandler.java
View file @
c647aeb9
package
com
.
gic
.
enterprise
.
exception
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintWriter
;
import
java.util.List
;
import
java.util.Set
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.ConstraintViolation
;
import
javax.validation.ConstraintViolationException
;
...
...
@@ -25,33 +22,12 @@ import com.gic.enterprise.error.ErrorCode;
*
* @author hua
*
*/
@ControllerAdvice
@ResponseBody
*/
public
class
GlobalExceptionHandler
{
private
static
Logger
logger
=
LogManager
.
getLogger
(
GlobalExceptionHandler
.
class
);
@ExceptionHandler
(
Exception
.
class
)
public
RestResponse
controllerException
(
HttpServletResponse
response
,
Exception
ex
)
{
logger
.
error
(
"err"
,
ex
);
RestResponse
failureResponse
=
getRestResponse
(
ErrorCode
.
SYSTEM_ERROR
.
getCode
(),
ErrorCode
.
SYSTEM_ERROR
.
getMsg
());
StringBuilder
sb
=
new
StringBuilder
();
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
try
(
PrintWriter
printWriter
=
new
PrintWriter
(
baos
))
{
logger
.
warn
(
"e"
,
ex
);
}
try
{
sb
.
append
(
baos
.
toString
());
}
catch
(
Exception
ignored
)
{
}
if
(
sb
.
length
()
==
0
)
{
sb
.
append
(
ex
.
getMessage
());
}
// 输出详细错误信息,便于调试
failureResponse
.
setDetailError
(
sb
.
toString
());
return
failureResponse
;
}
/**
* 参数校验异常统一处理
* @param e
...
...
gic-enterprise-common/src/main/java/com/gic/enterprise/interceptor/AuthInterceptor.java
View file @
c647aeb9
...
...
@@ -88,8 +88,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
return
true
;
}
if
(
userDetail
==
null
||
userDetail
.
getUserInfo
()
==
null
)
{
response
.
setStatus
(
6666
);
response
.
sendError
(
6666
,
"登录信息不存在,请登录"
);
throw
new
CommonException
(
ErrorCode
.
LOGIN_INVALID
.
getErrorCode
(),
"登录信息不存在,请登录"
);
}
request
.
setAttribute
(
"user"
,
userDetail
);
...
...
@@ -111,8 +109,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
//判断是否有权限
Map
<
String
,
Object
>
menuUrlMap
=
userDetail
.
getMenuUrlMap
();
if
(
menuUrlMap
==
null
||
menuUrlMap
.
isEmpty
())
{
response
.
setStatus
(
0003
);
response
.
sendError
(
0003
,
"sorry,您无该页面的访问权限,请联系超级管理员!"
);
throw
new
CommonException
(
ErrorCode
.
SYSTEM_ERROR
.
getErrorCode
(),
"sorry,您无该页面的访问权限,请联系超级管理员!"
);
}
...
...
@@ -120,16 +116,12 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
//说明是操作项
//如果匹配上了,说明是没权限
if
(
menuUrlMap
.
containsKey
(
uri
))
{
response
.
setStatus
(
0003
);
response
.
sendError
(
0003
,
"sorry,您无该页面的访问权限,请联系超级管理员!"
);
throw
new
CommonException
(
ErrorCode
.
SYSTEM_ERROR
.
getErrorCode
(),
"sorry,您无该页面的访问权限,请联系超级管理员!"
);
}
}
else
{
//说明是页面
//如果没有匹配上,说明没权限
if
(!
menuUrlMap
.
containsKey
(
uri
))
{
response
.
setStatus
(
0003
);
response
.
sendError
(
0003
,
"sorry,您无该页面的访问权限,请联系超级管理员!"
);
throw
new
CommonException
(
ErrorCode
.
SYSTEM_ERROR
.
getErrorCode
(),
"sorry,您无该页面的访问权限,请联系超级管理员!"
);
}
}
...
...
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