diff --git a/src/main/java/eu/openaire/api/errors/ServiceExceptionHandler.java b/src/main/java/eu/openaire/api/errors/ServiceExceptionHandler.java index 77211e3..c01c7e2 100644 --- a/src/main/java/eu/openaire/api/errors/ServiceExceptionHandler.java +++ b/src/main/java/eu/openaire/api/errors/ServiceExceptionHandler.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.WebRequest; +import org.springframework.web.servlet.resource.NoResourceFoundException; import java.util.Date; import java.util.stream.Collectors; @@ -42,6 +43,11 @@ public class ServiceExceptionHandler { return this.handleException(message, request, HttpStatus.BAD_REQUEST); } + @ExceptionHandler(NoResourceFoundException.class) + public ResponseEntity handleNoResourceFoundExceptions(NoResourceFoundException e, WebRequest request) { + return this.handleException(e.getMessage(), request, HttpStatus.METHOD_NOT_ALLOWED); + } + @ExceptionHandler(Exception.class) public ResponseEntity handleAllOtherExceptions(Exception e, WebRequest request) { e.printStackTrace();