Commit e460a5ef by 段启岩

添加调试模式

parent 4dde1cc5
package cn.meteor.beyondclouds.common.handler; package cn.meteor.beyondclouds.common.handler;
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.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.web.HttpRequestMethodNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
...@@ -15,16 +17,30 @@ import javax.servlet.http.HttpServletRequest; ...@@ -15,16 +17,30 @@ import javax.servlet.http.HttpServletRequest;
*/ */
@RestControllerAdvice @RestControllerAdvice
public class GlobalExceptionHandler { public class GlobalExceptionHandler {
private BeyondCloudsProperties beyondCloudsProperties;
@Autowired
public GlobalExceptionHandler(BeyondCloudsProperties beyondCloudsProperties) {
this.beyondCloudsProperties = beyondCloudsProperties;
}
@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();
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());
} else if (e instanceof HttpRequestMethodNotSupportedException){ } else if (e instanceof HttpRequestMethodNotSupportedException){
return Response.error(ErrorCode.OPERATION_FAILED.code(), e.getMessage()); return Response.error(ErrorCode.OPERATION_FAILED.code(), e.getMessage());
} else { } else {
if (debugMode) {
return Response.error(ErrorCode.OPERATION_FAILED.code(), e.getMessage());
} else {
return Response.error(); return Response.error();
} }
} }
}
} }
...@@ -27,6 +27,11 @@ public class BeyondCloudsProperties { ...@@ -27,6 +27,11 @@ public class BeyondCloudsProperties {
} }
/** /**
* debug模式开关
*/
private Boolean debug;
/**
* 认证配置 * 认证配置
*/ */
private AuthProperties auth; private AuthProperties auth;
......
...@@ -27,6 +27,7 @@ mybatis-plus: ...@@ -27,6 +27,7 @@ mybatis-plus:
mapper-locations: classpath*:cn/meteor/beyondclouds/modules/**/xml/*.xml mapper-locations: classpath*:cn/meteor/beyondclouds/modules/**/xml/*.xml
beyondclouds: beyondclouds:
debug: true
auth: auth:
qq: qq:
client-id: 101846021 client-id: 101846021
......
...@@ -27,6 +27,7 @@ mybatis-plus: ...@@ -27,6 +27,7 @@ mybatis-plus:
mapper-locations: classpath*:cn/meteor/beyondclouds/modules/**/xml/*.xml mapper-locations: classpath*:cn/meteor/beyondclouds/modules/**/xml/*.xml
beyondclouds: beyondclouds:
debug: true
auth: auth:
qq: qq:
client-id: 101846021 client-id: 101846021
......
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