fix: suppress stack trace on 404 NoResourceFoundException

Add a @RestControllerAdvice that catches NoResourceFoundException and
returns a clean 404 with a single DEBUG log instead of a full stack trace.
Handles browser devtools requests for .js.map files and similar missing
static resources.
This commit is contained in:
2026-05-01 11:08:00 +02:00
parent 505725f38d
commit 5306c54c0b
@@ -0,0 +1,22 @@
package dev.kruhlmann.imgfloat.config;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException;
@RestControllerAdvice
public class GlobalExceptionHandler {
private static final Logger LOG = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(NoResourceFoundException.class)
public ResponseEntity<Void> handleNoResource(NoResourceFoundException ex, HttpServletRequest request) {
LOG.debug("404 Not Found: {}", request.getRequestURI());
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
}