更新总异常处理类,添加IO流异常处理
parent
10af5ff706
commit
dcc3a6e727
|
@ -6,6 +6,7 @@ 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.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName:
|
* @ClassName:
|
||||||
|
@ -15,28 +16,74 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
*/
|
*/
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class GlobalExceptionHandler {
|
public class GlobalExceptionHandler extends Throwable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理 业务异常
|
* 错误码
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(ServiceException.class)
|
private Integer code;
|
||||||
public Result serviceExceptionHandler(ServiceException serviceException, HttpServletRequest request) {
|
|
||||||
String requestURI = request.getRequestURI();
|
/**
|
||||||
log.error("请求地址'{}',业务处理失败'{}'", requestURI, serviceException.getMessage());
|
* 错误提示
|
||||||
return Result.error(Result.FAIL, serviceException.getMessage());
|
*/
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误明细,内部调试错误
|
||||||
|
* <p>
|
||||||
|
*/
|
||||||
|
private String detailMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 空构造方法,避免反序列化问题
|
||||||
|
*/
|
||||||
|
public void IOException() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
public void IOException(String message) {
|
||||||
// /**
|
this.message = message;
|
||||||
// * 处理 业务异常
|
}
|
||||||
// * @return
|
|
||||||
// */
|
public void IOException(String message, Integer code) {
|
||||||
// @ExceptionHandler(Exception.class)
|
this.message = message;
|
||||||
// public Result exceptionHandler() {
|
this.code = code;
|
||||||
//
|
}
|
||||||
// return Result.error();
|
|
||||||
// }
|
public String getDetailMessage() {
|
||||||
|
return detailMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalExceptionHandler setDetailMessage(String detailMessage) {
|
||||||
|
this.detailMessage = detailMessage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalExceptionHandler setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理 IO流异常
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ExceptionHandler(IOException.class)
|
||||||
|
public Result ioExceptionHandler(IOException ioException,HttpServletRequest request) {
|
||||||
|
String requestURI = request.getRequestURI();
|
||||||
|
log.error("请求路径:【{}】,IO流处理异常:【{}】",requestURI,ioException.getMessage());
|
||||||
|
return Result.error(Result.FAIL, ioException.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue