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
ded82077
Commit
ded82077
authored
Nov 14, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
2dbcd72b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
1 deletion
+17
-1
GlobalExceptionHandler.java
...iaoqi/security/common/handler/GlobalExceptionHandler.java
+10
-0
PlatformExceptionHandler.java
...oqi/security/common/handler/PlatformExceptionHandler.java
+7
-1
No files found.
ace-common/src/main/java/com/github/wxiaoqi/security/common/handler/GlobalExceptionHandler.java
View file @
ded82077
...
@@ -19,6 +19,8 @@ import org.springframework.web.context.request.WebRequest;
...
@@ -19,6 +19,8 @@ import org.springframework.web.context.request.WebRequest;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
static
org
.
springframework
.
http
.
HttpStatus
.
NOT_EXTENDED
;
import
static
org
.
springframework
.
http
.
HttpStatus
.
NOT_EXTENDED
;
...
@@ -75,6 +77,14 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
...
@@ -75,6 +77,14 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
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
);
Throwable
cause
=
ex
.
getCause
();
if
(
cause
!=
null
&&
cause
.
toString
().
contains
(
"Exception"
))
{
StringWriter
stringWriter
=
new
StringWriter
();
cause
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
logger
.
error
(
cause
.
getMessage
(),
ex
);
HttpRequestUtil
.
httpGet
(
"http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content="
+
stringWriter
.
toString
());
return
new
BaseResponse
(
5000
,
"Server exception: "
+
ex
.
getMessage
());
}
HttpRequestUtil
.
httpGet
(
"http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content="
+
ex
);
HttpRequestUtil
.
httpGet
(
"http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content="
+
ex
);
return
new
BaseResponse
(
CommonConstants
.
EX_OTHER_CODE
,
ex
.
getMessage
());
return
new
BaseResponse
(
CommonConstants
.
EX_OTHER_CODE
,
ex
.
getMessage
());
}
}
...
...
ace-common/src/main/java/com/github/wxiaoqi/security/common/handler/PlatformExceptionHandler.java
View file @
ded82077
...
@@ -9,6 +9,9 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -9,6 +9,9 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
@RestControllerAdvice
(
"com.xxfc.platform"
)
@RestControllerAdvice
(
"com.xxfc.platform"
)
@Slf4j
@Slf4j
public
class
PlatformExceptionHandler
{
public
class
PlatformExceptionHandler
{
...
@@ -25,10 +28,13 @@ public class PlatformExceptionHandler {
...
@@ -25,10 +28,13 @@ public class PlatformExceptionHandler {
//服务器异常
//服务器异常
@ExceptionHandler
(
Exception
.
class
)
@ExceptionHandler
(
Exception
.
class
)
public
ObjectRestResponse
<?>
exceptionHandler
(
Exception
e
){
public
ObjectRestResponse
<?>
exceptionHandler
(
Exception
e
){
Throwable
cause
=
e
.
getCause
();
Throwable
cause
=
e
.
getCause
();
if
(
cause
!=
null
&&
cause
.
toString
().
contains
(
"Exception"
))
{
if
(
cause
!=
null
&&
cause
.
toString
().
contains
(
"Exception"
))
{
StringWriter
stringWriter
=
new
StringWriter
();
cause
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
log
.
error
(
cause
.
getMessage
(),
e
);
log
.
error
(
cause
.
getMessage
(),
e
);
HttpRequestUtil
.
httpGet
(
"http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content="
+
e
);
HttpRequestUtil
.
httpGet
(
"http://10.5.52.3:8765/api/universal/mail/app/unauth/send?toUser=jiaoruizhen@126.com&subject=服务器异常&content="
+
stringWriter
.
toString
()
);
return
assembleResult
(
ObjectRestResponse
.
createFailedResult
(
5000
,
"服务器开小差了,请稍后重试!"
),
"Server exception: "
+
e
.
getMessage
());
return
assembleResult
(
ObjectRestResponse
.
createFailedResult
(
5000
,
"服务器开小差了,请稍后重试!"
),
"Server exception: "
+
e
.
getMessage
());
}
}
log
.
error
(
"Server exception: "
,
e
);
log
.
error
(
"Server exception: "
,
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