Browse Source

err handler

master
gsd 11 months ago
parent
commit
ccf23b93eb
  1. 25
      src/main/java/app/exceptions/RestResponseStatusExceptionResolver.java

25
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;
}
}
Loading…
Cancel
Save