Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Patch v1.x console exception handler #7799

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}