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
5219b5c6
Commit
5219b5c6
authored
Aug 15, 2016
by
Jason Song
Committed by
GitHub
Aug 15, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #380 from nobodyiam/reformat
reformat
parents
07bd7c06
8fa2cc07
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
GlobalDefaultExceptionHandler.java
...ollo/common/controller/GlobalDefaultExceptionHandler.java
+8
-7
No files found.
apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/GlobalDefaultExceptionHandler.java
View file @
5219b5c6
...
...
@@ -3,6 +3,9 @@ package com.ctrip.framework.apollo.common.controller;
import
com.google.gson.Gson
;
import
com.google.gson.reflect.TypeToken
;
import
com.ctrip.framework.apollo.common.exception.AbstractApolloHttpException
;
import
com.dianping.cat.Cat
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpHeaders
;
...
...
@@ -15,9 +18,6 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.client.HttpStatusCodeException
;
import
com.ctrip.framework.apollo.common.exception.AbstractApolloHttpException
;
import
com.dianping.cat.Cat
;
import
java.lang.reflect.Type
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
...
...
@@ -35,7 +35,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON;
@ControllerAdvice
public
class
GlobalDefaultExceptionHandler
{
private
Gson
gson
=
new
Gson
();
private
static
Type
mapType
=
new
TypeToken
<
Map
<
String
,
Object
>>()
{}.
getType
();
private
static
Type
mapType
=
new
TypeToken
<
Map
<
String
,
Object
>>()
{
}.
getType
();
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
GlobalDefaultExceptionHandler
.
class
);
...
...
@@ -87,9 +88,9 @@ public class GlobalDefaultExceptionHandler {
Map
<
String
,
Object
>
errorAttributes
=
new
HashMap
<>();
//如果是admin server引起的异常,则显示内部的异常信息
if
(
ex
instanceof
HttpStatusCodeException
)
{
errorAttributes
=
gson
.
fromJson
(((
HttpStatusCodeException
)
ex
).
getResponseBodyAsString
(),
mapType
);
status
=
((
HttpStatusCodeException
)
ex
).
getStatusCode
();
if
(
ex
instanceof
HttpStatusCodeException
)
{
errorAttributes
=
gson
.
fromJson
(((
HttpStatusCodeException
)
ex
).
getResponseBodyAsString
(),
mapType
);
status
=
((
HttpStatusCodeException
)
ex
).
getStatusCode
();
}
else
{
errorAttributes
.
put
(
"status"
,
status
.
value
());
errorAttributes
.
put
(
"message"
,
message
);
...
...
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