mirror of
https://github.com/imgfloat/server.git
synced 2026-06-22 21:01:23 +00:00
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user