Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
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
youjj
cloud-platform
Commits
7852ec69
Commit
7852ec69
authored
Nov 12, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master-bacground-im' into dev
parents
befc49d0
2002770e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
1 deletion
+14
-1
GlobalExceptionHandler.java
...iaoqi/security/common/handler/GlobalExceptionHandler.java
+14
-1
No files found.
ace-common/src/main/java/com/github/wxiaoqi/security/common/handler/GlobalExceptionHandler.java
View file @
7852ec69
...
@@ -5,9 +5,11 @@ import com.github.wxiaoqi.security.common.exception.BaseException;
...
@@ -5,9 +5,11 @@ import com.github.wxiaoqi.security.common.exception.BaseException;
import
com.github.wxiaoqi.security.common.exception.auth.ClientTokenException
;
import
com.github.wxiaoqi.security.common.exception.auth.ClientTokenException
;
import
com.github.wxiaoqi.security.common.exception.auth.UserInvalidException
;
import
com.github.wxiaoqi.security.common.exception.auth.UserInvalidException
;
import
com.github.wxiaoqi.security.common.exception.auth.UserTokenException
;
import
com.github.wxiaoqi.security.common.exception.auth.UserTokenException
;
import
com.github.wxiaoqi.security.common.log.Impl.MailServiceImpl
;
import
com.github.wxiaoqi.security.common.msg.BaseResponse
;
import
com.github.wxiaoqi.security.common.msg.BaseResponse
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
...
@@ -21,7 +23,8 @@ import javax.servlet.http.HttpServletResponse;
...
@@ -21,7 +23,8 @@ import javax.servlet.http.HttpServletResponse;
@ResponseBody
@ResponseBody
public
class
GlobalExceptionHandler
{
public
class
GlobalExceptionHandler
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
GlobalExceptionHandler
.
class
);
private
Logger
logger
=
LoggerFactory
.
getLogger
(
GlobalExceptionHandler
.
class
);
@Autowired
MailServiceImpl
mailService
;
@ExceptionHandler
(
ClientTokenException
.
class
)
@ExceptionHandler
(
ClientTokenException
.
class
)
public
BaseResponse
clientTokenExceptionHandler
(
HttpServletResponse
response
,
ClientTokenException
ex
)
{
public
BaseResponse
clientTokenExceptionHandler
(
HttpServletResponse
response
,
ClientTokenException
ex
)
{
response
.
setStatus
(
403
);
response
.
setStatus
(
403
);
...
@@ -49,6 +52,7 @@ public class GlobalExceptionHandler {
...
@@ -49,6 +52,7 @@ public class GlobalExceptionHandler {
if
(
0
==
ex
.
getStatus
())
{
if
(
0
==
ex
.
getStatus
())
{
response
.
setStatus
(
500
);
response
.
setStatus
(
500
);
}
}
sendEmail
(
ex
);
return
new
BaseResponse
(
ex
.
getStatus
(),
ex
.
getMessage
());
return
new
BaseResponse
(
ex
.
getStatus
(),
ex
.
getMessage
());
}
}
...
@@ -56,7 +60,16 @@ public class GlobalExceptionHandler {
...
@@ -56,7 +60,16 @@ public class GlobalExceptionHandler {
public
BaseResponse
otherExceptionHandler
(
HttpServletResponse
response
,
Exception
ex
)
{
public
BaseResponse
otherExceptionHandler
(
HttpServletResponse
response
,
Exception
ex
)
{
response
.
setStatus
(
500
);
response
.
setStatus
(
500
);
logger
.
error
(
ex
.
getMessage
(),
ex
);
logger
.
error
(
ex
.
getMessage
(),
ex
);
sendEmail
(
ex
);
return
new
BaseResponse
(
CommonConstants
.
EX_OTHER_CODE
,
ex
.
getMessage
());
return
new
BaseResponse
(
CommonConstants
.
EX_OTHER_CODE
,
ex
.
getMessage
());
}
}
public
void
sendEmail
(
Exception
ex
)
{
try
{
logger
.
info
(
"发送异常邮件,邮件内容:【服务器异常】: {}"
,
ex
.
getMessage
()
+
":"
+
ex
);
mailService
.
sendSimpleMail
(
"jiaoruizhen@126.com"
,
"服务器异常"
,
ex
.
getMessage
()
+
":"
+
ex
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"发送异常邮件失败,异常信息: {}"
,
e
);
}
}
}
}
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