Skip to content

Commit

Permalink
do not set response when ClientAbortException (#7799)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrlw authored Mar 7, 2022
1 parent 55cad90 commit adebab9
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

import com.alibaba.nacos.auth.exception.AccessException;
import com.alibaba.nacos.common.utils.ExceptionUtil;

import javax.servlet.http.HttpServletRequest;

import org.apache.catalina.connector.ClientAbortException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
Expand All @@ -37,18 +41,25 @@ public class ConsoleExceptionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleExceptionHandler.class);

@ExceptionHandler(AccessException.class)
private ResponseEntity<String> handleAccessException(AccessException e) {
private ResponseEntity<String> handleAccessException(HttpServletRequest req, AccessException e) {
LOGGER.error("CONSOLE - access denied, request: {} from {}", req.getRequestURI(), req.getRemoteHost(), e);
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(e.getErrMsg());
}

@ExceptionHandler(IllegalArgumentException.class)
private ResponseEntity<String> handleIllegalArgumentException(IllegalArgumentException e) {
private ResponseEntity<String> handleIllegalArgumentException(HttpServletRequest req, IllegalArgumentException e) {
LOGGER.error("CONSOLE - illegal argument, request: {} from {}", req.getRequestURI(), req.getRemoteHost(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ExceptionUtil.getAllExceptionMsg(e));
}

@ExceptionHandler(ClientAbortException.class)
private void handleClientAbortException(HttpServletRequest req, ClientAbortException e) {
LOGGER.error("CONSOLE - client abort, request: {} from {}", req.getRequestURI(), req.getRemoteHost(), e);
}

@ExceptionHandler(Exception.class)
private ResponseEntity<String> handleException(Exception e) {
LOGGER.error("CONSOLE", e);
private ResponseEntity<String> handleException(HttpServletRequest req, Exception e) {
LOGGER.error("CONSOLE - unknown exception, request: {} from {}", req.getRequestURI(), req.getRemoteHost(), e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ExceptionUtil.getAllExceptionMsg(e));
}
}

0 comments on commit adebab9

Please sign in to comment.