From b9690f4560371768f9c01fe711be814edcfc28b1 Mon Sep 17 00:00:00 2001 From: JoungWoo Lee Date: Tue, 4 Mar 2025 19:18:57 +0900 Subject: [PATCH] =?UTF-8?q?feat(#37):=20prometheus=20=EC=97=94=EB=93=9C?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=98=88=EC=99=B8=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/GlobalExceptionHandler.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/urdego/urdego_content_service/common/exception/GlobalExceptionHandler.java b/src/main/java/io/urdego/urdego_content_service/common/exception/GlobalExceptionHandler.java index 84c1833..a0ed62d 100644 --- a/src/main/java/io/urdego/urdego_content_service/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/io/urdego/urdego_content_service/common/exception/GlobalExceptionHandler.java @@ -2,6 +2,7 @@ import feign.FeignException; import io.urdego.urdego_content_service.common.exception.content.UserContentException; +import jakarta.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -11,7 +12,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; - import java.util.stream.Collectors; import static org.springframework.http.HttpStatus.BAD_REQUEST; @@ -85,5 +85,21 @@ public ResponseEntity handleFeignException(FeignException e) { return ResponseEntity.badRequest().body(error); } + + @ExceptionHandler(Exception.class) + public ResponseEntity handleException(Exception e, HttpServletRequest request) { + + String requestUri = request.getRequestURI(); + + // Prometheus 요청 예외 처리 제외 + if (requestUri.startsWith("/actuator/prometheus")) { + return ResponseEntity.status(HttpStatus.OK).build(); + } + + ErrorResponse error = + ErrorResponse.from(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Internal Server Error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error); + } }