Commit 96d04faf by 张乐 Committed by GitHub

Merge pull request #381 from nobodyiam/global-exception-handler-fix

fix the potential error when handling exceptions
parents 5219b5c6 eaa877cf
...@@ -86,12 +86,20 @@ public class GlobalDefaultExceptionHandler { ...@@ -86,12 +86,20 @@ public class GlobalDefaultExceptionHandler {
Map<String, Object> errorAttributes = new HashMap<>(); Map<String, Object> errorAttributes = new HashMap<>();
boolean errorHandled = false;
//如果是admin server引起的异常,则显示内部的异常信息
if (ex instanceof HttpStatusCodeException) { if (ex instanceof HttpStatusCodeException) {
errorAttributes = gson.fromJson(((HttpStatusCodeException) ex).getResponseBodyAsString(), mapType); try {
status = ((HttpStatusCodeException) ex).getStatusCode(); //try to extract the original error info if it is thrown from apollo programs, e.g. admin service
} else { errorAttributes = gson.fromJson(((HttpStatusCodeException) ex).getResponseBodyAsString(), mapType);
status = ((HttpStatusCodeException) ex).getStatusCode();
errorHandled = true;
} catch (Throwable th) {
//ignore
}
}
if (!errorHandled) {
errorAttributes.put("status", status.value()); errorAttributes.put("status", status.value());
errorAttributes.put("message", message); errorAttributes.put("message", message);
errorAttributes.put("timestamp", errorAttributes.put("timestamp",
......
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