Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
fad1f8f0
Commit
fad1f8f0
authored
Feb 03, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加未知异常的详细信息,方便调试
parent
ff564007
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
src/main/java/cn/meteor/beyondclouds/common/handler/GlobalExceptionHandler.java
+9
-6
No files found.
src/main/java/cn/meteor/beyondclouds/common/handler/GlobalExceptionHandler.java
View file @
fad1f8f0
package
cn
.
meteor
.
beyondclouds
.
common
.
handler
;
package
cn
.
meteor
.
beyondclouds
.
common
.
handler
;
import
cn.meteor.beyondclouds.common.enums.ErrorCode
;
import
cn.meteor.beyondclouds.config.properties.BeyondCloudsProperties
;
import
cn.meteor.beyondclouds.config.properties.BeyondCloudsProperties
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.common.enums.ErrorCode
;
import
cn.meteor.beyondclouds.core.exception.ServiceException
;
import
cn.meteor.beyondclouds.core.exception.ServiceException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.HttpRequestMethodNotSupportedException
;
import
org.springframework.web.HttpRequestMethodNotSupportedException
;
...
@@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
...
@@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
/**
/**
* 全局异常捕获器,捕获在Controller层未处理异常
* 全局异常捕获器,捕获在Controller层未处理异常
...
@@ -27,9 +29,7 @@ public class GlobalExceptionHandler {
...
@@ -27,9 +29,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler
(
value
=
Exception
.
class
)
@ExceptionHandler
(
value
=
Exception
.
class
)
public
Response
<
String
>
exceptionHandler
(
HttpServletRequest
request
,
Exception
e
)
{
public
Response
<
String
>
exceptionHandler
(
HttpServletRequest
request
,
Exception
e
)
{
boolean
debugMode
=
beyondCloudsProperties
.
getDebug
();
boolean
debugMode
=
beyondCloudsProperties
.
getDebug
();
if
(
debugMode
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
if
(
e
instanceof
ServiceException
)
{
if
(
e
instanceof
ServiceException
)
{
ServiceException
exception
=
(
ServiceException
)
e
;
ServiceException
exception
=
(
ServiceException
)
e
;
return
Response
.
error
(
exception
.
getErrorCode
(),
exception
.
getErrorMsg
());
return
Response
.
error
(
exception
.
getErrorCode
(),
exception
.
getErrorMsg
());
...
@@ -37,10 +37,12 @@ public class GlobalExceptionHandler {
...
@@ -37,10 +37,12 @@ public class GlobalExceptionHandler {
return
Response
.
error
(
ErrorCode
.
OPERATION_FAILED
.
code
(),
e
.
getMessage
());
return
Response
.
error
(
ErrorCode
.
OPERATION_FAILED
.
code
(),
e
.
getMessage
());
}
else
{
}
else
{
if
(
debugMode
)
{
if
(
debugMode
)
{
return
Response
.
error
(
ErrorCode
.
OPERATION_FAILED
.
code
(),
e
.
getMessage
());
ByteArrayOutputStream
byteBuff
=
new
ByteArrayOutputStream
();
e
.
printStackTrace
(
new
PrintStream
(
byteBuff
));
return
Response
.
error
(
ErrorCode
.
OPERATION_FAILED
.
code
(),
byteBuff
.
toString
());
}
else
{
}
else
{
return
Response
.
error
();
return
Response
.
error
();
}
}
}
}
}
}
}
}
\ No newline at end of file
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