Commit fad1f8f0 by 段启岩

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

parent ff564007
package cn.meteor.beyondclouds.common.handler;
import cn.meteor.beyondclouds.common.enums.ErrorCode;
import cn.meteor.beyondclouds.config.properties.BeyondCloudsProperties;
import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.common.enums.ErrorCode;
import cn.meteor.beyondclouds.core.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.HttpRequestMethodNotSupportedException;
......@@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
/**
* 全局异常捕获器,捕获在Controller层未处理异常
......@@ -27,9 +29,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(value = Exception.class)
public Response<String> exceptionHandler(HttpServletRequest request, Exception e) {
boolean debugMode = beyondCloudsProperties.getDebug();
if (debugMode) {
e.printStackTrace();
}
e.printStackTrace();
if (e instanceof ServiceException) {
ServiceException exception = (ServiceException) e;
return Response.error(exception.getErrorCode(), exception.getErrorMsg());
......@@ -37,10 +37,12 @@ public class GlobalExceptionHandler {
return Response.error(ErrorCode.OPERATION_FAILED.code(), e.getMessage());
} else {
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 {
return Response.error();
}
}
}
}
}
\ No newline at end of file
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