Commit b7cc6a28 by 段启岩

Merge remote-tracking branch 'origin/qiyanduan02-03'

# Conflicts:
#	src/main/resources/application-prod.yml
parents ce68c2ff 7c69194c
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,9 @@ import org.springframework.web.bind.annotation.ExceptionHandler; ...@@ -10,6 +10,9 @@ 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.IOException;
import java.io.PrintStream;
/** /**
* 全局异常捕获器,捕获在Controller层未处理异常 * 全局异常捕获器,捕获在Controller层未处理异常
...@@ -27,9 +30,7 @@ public class GlobalExceptionHandler { ...@@ -27,9 +30,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 +38,15 @@ public class GlobalExceptionHandler { ...@@ -37,7 +38,15 @@ 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));
String errTrace = byteBuff.toString();
try {
byteBuff.close();
} catch (IOException ex) {
ex.printStackTrace();
}
return Response.error(ErrorCode.OPERATION_FAILED.code(), errTrace);
} else { } else {
return Response.error(); return Response.error();
} }
......
...@@ -2,8 +2,8 @@ spring: ...@@ -2,8 +2,8 @@ spring:
datasource: datasource:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username: root username: beyond
password: 2018006709 password: Beyond2020#
swagger: swagger:
enable: true enable: true
......
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