Add method not allowed exception

This commit is contained in:
Serafeim Chatzopoulos 2024-06-26 18:55:14 +03:00
parent 517dd3c38f
commit f3ba74fe4a
1 changed files with 6 additions and 0 deletions

View File

@ -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<ErrorResponse> handleNoResourceFoundExceptions(NoResourceFoundException e, WebRequest request) {
return this.handleException(e.getMessage(), request, HttpStatus.METHOD_NOT_ALLOWED);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleAllOtherExceptions(Exception e, WebRequest request) {
e.printStackTrace();