Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -168,6 +170,16 @@ public ResponseEntity<ErrorResponse> 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<Void> handleUnknownPath(Exception ex, WebRequest request) {
log.warn("Unknown path {}", request.getDescription(false));
return ResponseEntity.notFound().build();
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleGlobalException(Exception ex, WebRequest request) {
// Log before building the body. A later failure to write ErrorResponse (for example
Expand Down