From ccf23b93ebd64bacaba79bc68a4126f8c926aa3f Mon Sep 17 00:00:00 2001 From: gsd Date: Wed, 24 Apr 2024 22:56:30 +0300 Subject: [PATCH] err handler --- .../RestResponseStatusExceptionResolver.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/app/exceptions/RestResponseStatusExceptionResolver.java diff --git a/src/main/java/app/exceptions/RestResponseStatusExceptionResolver.java b/src/main/java/app/exceptions/RestResponseStatusExceptionResolver.java new file mode 100644 index 0000000..75ca727 --- /dev/null +++ b/src/main/java/app/exceptions/RestResponseStatusExceptionResolver.java @@ -0,0 +1,25 @@ +package app.exceptions; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver; + +import java.util.UUID; + +@Component +public class RestResponseStatusExceptionResolver extends AbstractHandlerExceptionResolver { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + @Override + protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { + UUID uuid = UUID.randomUUID(); + logger.error("[{}] Found error in request {} with path {}", uuid, request.getMethod(), request.getRequestURI()); + logger.error("["+uuid+"]", ex); + logger.error("[{}] Request ended with code: {}", uuid, response.getStatus()); + return null; + } +}