Commit fad1f8f0 by 段启岩

添加未知异常的详细信息,方便调试

parent ff564007
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,7 +37,9 @@ public class GlobalExceptionHandler { ...@@ -37,7 +37,9 @@ 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();
} }
......
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