diff --git a/src/main/java/page/clab/api/global/common/slack/application/SlackService.java b/src/main/java/page/clab/api/global/common/slack/application/SlackService.java index 0ad64dcbd..0dfdff842 100644 --- a/src/main/java/page/clab/api/global/common/slack/application/SlackService.java +++ b/src/main/java/page/clab/api/global/common/slack/application/SlackService.java @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; @Service @Slf4j @@ -124,14 +125,17 @@ private List createErrorBlocks(HttpServletRequest request, Exceptio Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String username = (authentication == null || authentication.getName() == null) ? "anonymous" : authentication.getName(); + String errorMessage = e.getMessage() == null ? "No error message provided" : e.getMessage(); + String detailedMessage = extractMessageAfterException(errorMessage); + log.error("Server Error: {}", detailedMessage); return Arrays.asList( section(section -> section.text(markdownText(":firecracker: *Server Error*"))), section(section -> section.fields(Arrays.asList( markdownText("*User:*\n" + username), markdownText("*Endpoint:*\n[" + httpMethod + "] " + requestUrl) ))), - section(section -> section.text(markdownText("*Error Message:*\n" + e.getMessage().split(":")[1]))), - section(section -> section.text(markdownText("*Stack Trace:*\n```" + Arrays.toString(e.getStackTrace()) + "```"))) + section(section -> section.text(markdownText("*Error Message:*\n" + detailedMessage))), + section(section -> section.text(markdownText("*Stack Trace:*\n```" + getStackTraceSummary(e) + "```"))) ); } @@ -226,6 +230,19 @@ private List createServerStartBlocks() { ); } + private String extractMessageAfterException(String message) { + String exceptionIndicator = "Exception:"; + int exceptionIndex = message.indexOf(exceptionIndicator); + return exceptionIndex == -1 ? message : message.substring(exceptionIndex + exceptionIndicator.length()).trim(); + } + + private String getStackTraceSummary(Exception e) { + return Arrays.stream(e.getStackTrace()) + .limit(10) + .map(StackTraceElement::toString) + .collect(Collectors.joining("\n")); + } + private String formatMemoryUsage(MemoryUsage memoryUsage) { long usedMemory = memoryUsage.getUsed() / (1024 * 1024); long maxMemory = memoryUsage.getMax() / (1024 * 1024); diff --git a/src/main/java/page/clab/api/global/handler/GlobalExceptionHandler.java b/src/main/java/page/clab/api/global/handler/GlobalExceptionHandler.java index 05df9d8bc..6c52d31b5 100644 --- a/src/main/java/page/clab/api/global/handler/GlobalExceptionHandler.java +++ b/src/main/java/page/clab/api/global/handler/GlobalExceptionHandler.java @@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.authentication.BadCredentialsException; @@ -67,6 +68,7 @@ import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; +import java.util.concurrent.CompletionException; @RestControllerAdvice(basePackages = "page.clab.api") @RequiredArgsConstructor @@ -169,11 +171,14 @@ public ErrorResponse conflictException(HttpServletResponse response, Exception e IllegalStateException.class, FileUploadFailException.class, DataIntegrityViolationException.class, + IncorrectResultSizeDataAccessException.class, + ArrayIndexOutOfBoundsException.class, IOException.class, WebClientRequestException.class, TransactionSystemException.class, SecurityException.class, CustomOptimisticLockingFailureException.class, + CompletionException.class, EncryptionException.class, DecryptionException.class, Exception.class