diff --git a/src/main/java/dev/kruhlmann/imgfloat/config/GlobalExceptionHandler.java b/src/main/java/dev/kruhlmann/imgfloat/config/GlobalExceptionHandler.java new file mode 100644 index 0000000..f7f1b88 --- /dev/null +++ b/src/main/java/dev/kruhlmann/imgfloat/config/GlobalExceptionHandler.java @@ -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 handleNoResource(NoResourceFoundException ex, HttpServletRequest request) { + LOG.debug("404 Not Found: {}", request.getRequestURI()); + return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); + } +}