|
|
@ -2,6 +2,7 @@ package com.java3y.austin.web.exception;
|
|
|
|
|
|
|
|
|
|
|
|
import com.java3y.austin.common.enums.RespStatusEnum;
|
|
|
|
import com.java3y.austin.common.enums.RespStatusEnum;
|
|
|
|
import com.java3y.austin.common.vo.BasicResultVO;
|
|
|
|
import com.java3y.austin.common.vo.BasicResultVO;
|
|
|
|
|
|
|
|
import org.assertj.core.util.Throwables;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
@ -10,16 +11,13 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
|
|
|
import java.io.StringWriter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @author kl
|
|
|
|
* @author kl
|
|
|
|
* @version 1.0.0
|
|
|
|
* @version 1.0.0
|
|
|
|
* @description 拦截异常统一返回
|
|
|
|
* @description 拦截异常统一返回
|
|
|
|
* @date 2023/2/9 19:03
|
|
|
|
* @date 2023/2/9 19:03
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ControllerAdvice
|
|
|
|
@ControllerAdvice(basePackages = "com.java3y.austin.web.controller")
|
|
|
|
@ResponseBody
|
|
|
|
@ResponseBody
|
|
|
|
public class ExceptionHandlerAdvice {
|
|
|
|
public class ExceptionHandlerAdvice {
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ExceptionHandlerAdvice.class);
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ExceptionHandlerAdvice.class);
|
|
|
@ -30,19 +28,16 @@ public class ExceptionHandlerAdvice {
|
|
|
|
@ExceptionHandler({Exception.class})
|
|
|
|
@ExceptionHandler({Exception.class})
|
|
|
|
@ResponseStatus(HttpStatus.OK)
|
|
|
|
@ResponseStatus(HttpStatus.OK)
|
|
|
|
public BasicResultVO exceptionResponse(Exception e) {
|
|
|
|
public BasicResultVO exceptionResponse(Exception e) {
|
|
|
|
StringWriter sw = new StringWriter();
|
|
|
|
BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_500, "\r\n" + Throwables.getStackTrace(e) + "\r\n");
|
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
|
log.error(Throwables.getStackTrace(e));
|
|
|
|
e.printStackTrace(pw);
|
|
|
|
|
|
|
|
BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_500, "\r\n" + sw + "\r\n");
|
|
|
|
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ExceptionHandler({CommonException.class})
|
|
|
|
@ExceptionHandler({CommonException.class})
|
|
|
|
@ResponseStatus(HttpStatus.OK)
|
|
|
|
@ResponseStatus(HttpStatus.OK)
|
|
|
|
public BasicResultVO commonResponse(CommonException ce) {
|
|
|
|
public BasicResultVO commonResponse(CommonException ce) {
|
|
|
|
BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_400, ce.getMessage());
|
|
|
|
BasicResultVO result = BasicResultVO.fail(RespStatusEnum.ERROR_400, Throwables.getStackTrace(ce));
|
|
|
|
log.error(ce.getMessage(), ce);
|
|
|
|
log.error(Throwables.getStackTrace(ce));
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|