diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/core/exception/GlobalExceptionHandler.java b/server/src/main/java/au/org/aodn/ogcapi/server/core/exception/GlobalExceptionHandler.java index cbd29162..d56dba9e 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/core/exception/GlobalExceptionHandler.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/core/exception/GlobalExceptionHandler.java @@ -6,6 +6,8 @@ import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.WebRequest; +import org.springframework.web.servlet.NoHandlerFoundException; +import org.springframework.web.servlet.resource.NoResourceFoundException; import au.org.aodn.ogcapi.server.core.model.ErrorResponse; import java.time.LocalDateTime; @@ -168,6 +170,16 @@ public ResponseEntity handleGeoserverLayersNotFoundException(Geos return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND); } + /** + * Unknown paths (for example internet scanner probes) are a client error, not a server error. + * Return an empty 404 so it works for any Accept header, and avoid ERROR level logging. + */ + @ExceptionHandler({NoResourceFoundException.class, NoHandlerFoundException.class}) + public ResponseEntity handleUnknownPath(Exception ex, WebRequest request) { + log.warn("Unknown path {}", request.getDescription(false)); + return ResponseEntity.notFound().build(); + } + @ExceptionHandler(Exception.class) public ResponseEntity handleGlobalException(Exception ex, WebRequest request) { // Log before building the body. A later failure to write ErrorResponse (for example