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