Commit e460a5ef by 段启岩

添加调试模式

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