|
@@ -4,6 +4,7 @@ import cn.hutool.core.exceptions.ExceptionUtil;
|
|
import com.fdkankan.common.constant.ServerCode;
|
|
import com.fdkankan.common.constant.ServerCode;
|
|
import com.fdkankan.common.response.ResultData;
|
|
import com.fdkankan.common.response.ResultData;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
@@ -17,14 +18,16 @@ import javax.servlet.http.HttpServletRequest;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class GlobalExceptionHandler {
|
|
public class GlobalExceptionHandler {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ResultData resultData;
|
|
/**
|
|
/**
|
|
* 处理未知异常
|
|
* 处理未知异常
|
|
*/
|
|
*/
|
|
@ResponseBody
|
|
@ResponseBody
|
|
@ExceptionHandler(value = Exception.class)
|
|
@ExceptionHandler(value = Exception.class)
|
|
- public ResultData exceptionHandler(HttpServletRequest httpServletRequest, Exception e) {
|
|
|
|
|
|
+ public String exceptionHandler(HttpServletRequest httpServletRequest, Exception e) {
|
|
log.error("服务错误:", e);
|
|
log.error("服务错误:", e);
|
|
- return ResultData.fail(ServerCode.SYSTEM_ERROR.code(), ExceptionUtil.stacktraceToString(e, 3000));
|
|
|
|
|
|
+ return resultData.error(ServerCode.SYSTEM_ERROR.code(), ExceptionUtil.stacktraceToString(e, 3000));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -32,8 +35,8 @@ public class GlobalExceptionHandler {
|
|
*/
|
|
*/
|
|
@ResponseBody
|
|
@ResponseBody
|
|
@ExceptionHandler(value = BusinessException.class)
|
|
@ExceptionHandler(value = BusinessException.class)
|
|
- public ResultData businessExceptionHandler(HttpServletRequest httpServletRequest, BusinessException e) {
|
|
|
|
|
|
+ public String businessExceptionHandler(HttpServletRequest httpServletRequest, BusinessException e) {
|
|
log.info("业务异常-----code:" + e.getCode() + "msg:" + e.getMsg());
|
|
log.info("业务异常-----code:" + e.getCode() + "msg:" + e.getMsg());
|
|
- return ResultData.fail(e.getCode(), e.getMsg());
|
|
|
|
|
|
+ return resultData.error(e.getCode(), e.getMsg());
|
|
}
|
|
}
|
|
}
|
|
}
|