Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
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
openSource
apollo
Commits
75bc0d00
Unverified
Commit
75bc0d00
authored
Jul 07, 2018
by
Jason Song
Committed by
GitHub
Jul 07, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1232 from nobodyiam/master
refactor GlobalDefaultExceptionHandler a little bit
parents
39638224
4cfbf1ed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
GlobalDefaultExceptionHandler.java
...ollo/common/controller/GlobalDefaultExceptionHandler.java
+11
-11
No files found.
apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/GlobalDefaultExceptionHandler.java
View file @
75bc0d00
...
@@ -28,6 +28,7 @@ import java.util.Map;
...
@@ -28,6 +28,7 @@ import java.util.Map;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
static
org
.
slf4j
.
event
.
Level
.*;
import
static
org
.
springframework
.
http
.
HttpStatus
.
BAD_REQUEST
;
import
static
org
.
springframework
.
http
.
HttpStatus
.
BAD_REQUEST
;
import
static
org
.
springframework
.
http
.
HttpStatus
.
FORBIDDEN
;
import
static
org
.
springframework
.
http
.
HttpStatus
.
FORBIDDEN
;
import
static
org
.
springframework
.
http
.
HttpStatus
.
INTERNAL_SERVER_ERROR
;
import
static
org
.
springframework
.
http
.
HttpStatus
.
INTERNAL_SERVER_ERROR
;
...
@@ -50,7 +51,7 @@ public class GlobalDefaultExceptionHandler {
...
@@ -50,7 +51,7 @@ public class GlobalDefaultExceptionHandler {
@ExceptionHandler
({
HttpRequestMethodNotSupportedException
.
class
,
HttpMediaTypeException
.
class
})
@ExceptionHandler
({
HttpRequestMethodNotSupportedException
.
class
,
HttpMediaTypeException
.
class
})
public
ResponseEntity
<
Map
<
String
,
Object
>>
badRequest
(
HttpServletRequest
request
,
public
ResponseEntity
<
Map
<
String
,
Object
>>
badRequest
(
HttpServletRequest
request
,
ServletException
ex
)
{
ServletException
ex
)
{
return
handleError
(
request
,
BAD_REQUEST
,
ex
,
Level
.
WARN
);
return
handleError
(
request
,
BAD_REQUEST
,
ex
,
WARN
);
}
}
@ExceptionHandler
(
HttpStatusCodeException
.
class
)
@ExceptionHandler
(
HttpStatusCodeException
.
class
)
...
@@ -68,13 +69,12 @@ public class GlobalDefaultExceptionHandler {
...
@@ -68,13 +69,12 @@ public class GlobalDefaultExceptionHandler {
//处理自定义Exception
//处理自定义Exception
@ExceptionHandler
({
AbstractApolloHttpException
.
class
})
@ExceptionHandler
({
AbstractApolloHttpException
.
class
})
public
ResponseEntity
<
Map
<
String
,
Object
>>
badRequest
(
HttpServletRequest
request
,
AbstractApolloHttpException
ex
)
{
public
ResponseEntity
<
Map
<
String
,
Object
>>
badRequest
(
HttpServletRequest
request
,
AbstractApolloHttpException
ex
)
{
return
handleError
(
request
,
ex
.
getHttpStatus
(),
ex
,
Level
.
ERROR
);
return
handleError
(
request
,
ex
.
getHttpStatus
(),
ex
);
}
}
private
ResponseEntity
<
Map
<
String
,
Object
>>
handleError
(
HttpServletRequest
request
,
private
ResponseEntity
<
Map
<
String
,
Object
>>
handleError
(
HttpServletRequest
request
,
HttpStatus
status
,
Throwable
ex
)
{
HttpStatus
status
,
Throwable
ex
)
{
return
handleError
(
request
,
status
,
ex
,
Level
.
ERROR
);
return
handleError
(
request
,
status
,
ex
,
ERROR
);
}
}
private
ResponseEntity
<
Map
<
String
,
Object
>>
handleError
(
HttpServletRequest
request
,
private
ResponseEntity
<
Map
<
String
,
Object
>>
handleError
(
HttpServletRequest
request
,
...
@@ -112,24 +112,24 @@ public class GlobalDefaultExceptionHandler {
...
@@ -112,24 +112,24 @@ public class GlobalDefaultExceptionHandler {
//打印日志, 其中logLevel为日志级别: ERROR/WARN/DEBUG/INFO/TRACE
//打印日志, 其中logLevel为日志级别: ERROR/WARN/DEBUG/INFO/TRACE
private
void
printLog
(
String
message
,
Throwable
ex
,
Level
logLevel
)
{
private
void
printLog
(
String
message
,
Throwable
ex
,
Level
logLevel
)
{
switch
(
logLevel
.
toString
()
)
{
switch
(
logLevel
)
{
case
"ERROR"
:
case
ERROR
:
logger
.
error
(
message
,
ex
);
logger
.
error
(
message
,
ex
);
break
;
break
;
case
"WARN"
:
case
WARN
:
logger
.
warn
(
message
,
ex
);
logger
.
warn
(
message
,
ex
);
break
;
break
;
case
"DEBUG"
:
case
DEBUG
:
logger
.
debug
(
message
,
ex
);
logger
.
debug
(
message
,
ex
);
break
;
break
;
case
"INFO"
:
case
INFO
:
logger
.
info
(
message
,
ex
);
logger
.
info
(
message
,
ex
);
break
;
break
;
case
"TRACE"
:
case
TRACE
:
logger
.
trace
(
message
,
ex
);
logger
.
trace
(
message
,
ex
);
break
;
break
;
}
}
Tracer
.
logError
(
ex
);
Tracer
.
logError
(
ex
);
}
}
...
...
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