|
|
|
@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
import org.springframework.web.context.request.async.AsyncRequestTimeoutException;
|
|
|
|
import org.springframework.web.context.request.async.AsyncRequestTimeoutException;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.validation.ConstraintViolation;
|
|
|
|
import javax.validation.ConstraintViolation;
|
|
|
|
import javax.validation.ConstraintViolationException;
|
|
|
|
import javax.validation.ConstraintViolationException;
|
|
|
|
|
|
|
|
|
|
|
|
@ -113,14 +114,20 @@ public class GlobalExceptionHandler {
|
|
|
|
* 拦截未知的运行时异常
|
|
|
|
* 拦截未知的运行时异常
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ExceptionHandler(RuntimeException.class)
|
|
|
|
@ExceptionHandler(RuntimeException.class)
|
|
|
|
public R<Void> handleRuntimeException(RuntimeException e, HttpServletRequest request) {
|
|
|
|
public R<Void> handleRuntimeException(RuntimeException e, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
|
|
|
if (response.getContentType().contains("text/event-stream")) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
String requestURI = request.getRequestURI();
|
|
|
|
String requestURI = request.getRequestURI();
|
|
|
|
log.error("请求地址'{}',发生未知异常.", requestURI, e);
|
|
|
|
log.error("请求地址'{}',发生未知异常.", requestURI, e);
|
|
|
|
return R.fail(e.getMessage());
|
|
|
|
return R.fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ExceptionHandler(AsyncRequestTimeoutException.class)
|
|
|
|
@ExceptionHandler(AsyncRequestTimeoutException.class)
|
|
|
|
public R<Void> handleRuntimeException(AsyncRequestTimeoutException e) {
|
|
|
|
public R<Void> handleAsyncRequestTimeoutException(AsyncRequestTimeoutException e, HttpServletResponse response) {
|
|
|
|
|
|
|
|
if (response.getContentType().contains("text/event-stream")) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
return R.fail(e.getMessage());
|
|
|
|
return R.fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -128,7 +135,10 @@ public class GlobalExceptionHandler {
|
|
|
|
* 系统异常
|
|
|
|
* 系统异常
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
|
public R<Void> handleException(Exception e, HttpServletRequest request) {
|
|
|
|
public R<Void> handleException(Exception e, HttpServletRequest request,HttpServletResponse response) {
|
|
|
|
|
|
|
|
if (response.getContentType().contains("text/event-stream")) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
String requestURI = request.getRequestURI();
|
|
|
|
String requestURI = request.getRequestURI();
|
|
|
|
log.error("请求地址'{}',发生系统异常.", requestURI, e);
|
|
|
|
log.error("请求地址'{}',发生系统异常.", requestURI, e);
|
|
|
|
return R.fail(e.getMessage());
|
|
|
|
return R.fail(e.getMessage());
|
|
|
|
|