diff --git a/server/src/main/java/server/haengdong/config/AdminInterceptor.java b/server/src/main/java/server/haengdong/config/AdminInterceptor.java index c78cd854e..a0542ed46 100644 --- a/server/src/main/java/server/haengdong/config/AdminInterceptor.java +++ b/server/src/main/java/server/haengdong/config/AdminInterceptor.java @@ -23,8 +23,6 @@ public AdminInterceptor(AuthService authService, AuthenticationExtractor authent @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { - log.debug("login request = {}", request.getRequestURI()); - String requestURI = request.getRequestURI(); if (requestURI.endsWith("/login")) { @@ -46,6 +44,7 @@ private void validateToken(HttpServletRequest request) { String tokenEventId = authService.findEventIdByToken(token); String eventId = request.getRequestURI().split("/")[3]; if (!tokenEventId.equals(eventId)) { + log.warn("[행사 접근 불가] Cookie EventId = {}, URL EventId = {}", tokenEventId, eventId); throw new AuthenticationException(HaengdongErrorCode.FORBIDDEN); } } diff --git a/server/src/main/java/server/haengdong/exception/GlobalExceptionHandler.java b/server/src/main/java/server/haengdong/exception/GlobalExceptionHandler.java index 7ed01c3c6..4d7dff45f 100644 --- a/server/src/main/java/server/haengdong/exception/GlobalExceptionHandler.java +++ b/server/src/main/java/server/haengdong/exception/GlobalExceptionHandler.java @@ -1,5 +1,8 @@ package server.haengdong.exception; +import jakarta.servlet.http.HttpServletRequest; +import java.io.BufferedReader; +import java.io.IOException; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; @@ -15,9 +18,16 @@ @RestControllerAdvice public class GlobalExceptionHandler { + private static final String LOG_FORMAT = """ + + [Request URI] {} {} + [Request Body] {} + [Error Message] {} + """; + @ExceptionHandler(AuthenticationException.class) - public ResponseEntity authenticationException(AuthenticationException e) { - log.warn(e.getMessage(), e); + public ResponseEntity authenticationException(HttpServletRequest req, AuthenticationException e) { + log.warn(LOG_FORMAT, req.getMethod(), req.getRequestURI(), getRequestBody(req), e.getMessage(), e); return ResponseEntity.status(HttpStatus.UNAUTHORIZED) .body(ErrorResponse.of(e.getErrorCode())); } @@ -55,16 +65,25 @@ public ResponseEntity handleMethodArgumentNotValidException(Metho } @ExceptionHandler(HaengdongException.class) - public ResponseEntity haengdongException(HaengdongException e) { - log.warn(e.getMessage(), e); + public ResponseEntity haengdongException(HttpServletRequest req, HaengdongException e) { + log.warn(LOG_FORMAT, req.getMethod(), req.getRequestURI(), getRequestBody(req), e.getMessage(), e); return ResponseEntity.badRequest() .body(ErrorResponse.of(e.getErrorCode())); } @ExceptionHandler(Exception.class) - public ResponseEntity handleException(Exception e) { - log.error(e.getMessage(), e); + public ResponseEntity handleException(HttpServletRequest req, Exception e) { + log.error(LOG_FORMAT, req.getMethod(), req.getRequestURI(), getRequestBody(req), e.getMessage(), e); return ResponseEntity.internalServerError() .body(ErrorResponse.of(HaengdongErrorCode.INTERNAL_SERVER_ERROR)); } + + private String getRequestBody(HttpServletRequest req) { + try (BufferedReader reader = req.getReader()) { + return reader.lines().collect(Collectors.joining(System.lineSeparator())); + } catch (IOException e) { + log.error("Failed to read request body", e); + return ""; + } + } } diff --git a/server/src/main/resources/config b/server/src/main/resources/config index 141eb40e8..e3e68ba63 160000 --- a/server/src/main/resources/config +++ b/server/src/main/resources/config @@ -1 +1 @@ -Subproject commit 141eb40e871cc9c3e172af46db29d90ac6448180 +Subproject commit e3e68ba63b49a7f6eaae8ccbd8c8af653ba34f3b