Commit 8fa2cc07 by Jason Song

reformat

parent 07bd7c06
...@@ -3,6 +3,9 @@ package com.ctrip.framework.apollo.common.controller; ...@@ -3,6 +3,9 @@ package com.ctrip.framework.apollo.common.controller;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
...@@ -15,9 +18,6 @@ import org.springframework.web.bind.annotation.ControllerAdvice; ...@@ -15,9 +18,6 @@ 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.client.HttpStatusCodeException; 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.lang.reflect.Type;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
...@@ -35,7 +35,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON; ...@@ -35,7 +35,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON;
@ControllerAdvice @ControllerAdvice
public class GlobalDefaultExceptionHandler { public class GlobalDefaultExceptionHandler {
private Gson gson = new Gson(); 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); private static final Logger logger = LoggerFactory.getLogger(GlobalDefaultExceptionHandler.class);
...@@ -87,9 +88,9 @@ public class GlobalDefaultExceptionHandler { ...@@ -87,9 +88,9 @@ public class GlobalDefaultExceptionHandler {
Map<String, Object> errorAttributes = new HashMap<>(); Map<String, Object> errorAttributes = new HashMap<>();
//如果是admin server引起的异常,则显示内部的异常信息 //如果是admin server引起的异常,则显示内部的异常信息
if (ex instanceof HttpStatusCodeException){ if (ex instanceof HttpStatusCodeException) {
errorAttributes = gson.fromJson(((HttpStatusCodeException)ex).getResponseBodyAsString(), mapType); errorAttributes = gson.fromJson(((HttpStatusCodeException) ex).getResponseBodyAsString(), mapType);
status = ((HttpStatusCodeException)ex).getStatusCode(); status = ((HttpStatusCodeException) ex).getStatusCode();
} else { } else {
errorAttributes.put("status", status.value()); errorAttributes.put("status", status.value());
errorAttributes.put("message", message); errorAttributes.put("message", message);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment