diff --git a/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/exception/ExceptionHandling.java b/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/exception/ExceptionHandling.java index bde1e09..ec563c8 100644 --- a/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/exception/ExceptionHandling.java +++ b/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/exception/ExceptionHandling.java @@ -2,7 +2,6 @@ package net.shyshkin.study.fullstack.supportportal.backend.exception; import com.auth0.jwt.exceptions.TokenExpiredException; import lombok.extern.slf4j.Slf4j; -import net.shyshkin.study.fullstack.supportportal.backend.controller.UserResource; import net.shyshkin.study.fullstack.supportportal.backend.domain.HttpResponse; import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.EmailExistsException; import net.shyshkin.study.fullstack.supportportal.backend.exception.domain.EmailNotFoundException; @@ -18,6 +17,7 @@ import org.springframework.security.authentication.LockedException; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.NoHandlerFoundException; import javax.persistence.NoResultException; import java.io.IOException; @@ -26,7 +26,7 @@ import java.util.Objects; import static org.springframework.http.HttpStatus.*; @Slf4j -@RestControllerAdvice(basePackageClasses = {UserResource.class}) +@RestControllerAdvice public class ExceptionHandling { private static final String ACCOUNT_LOCKED = "Your account has been locked. Please contact administration"; private static final String METHOD_IS_NOT_ALLOWED = "This request method is not allowed on this endpoint. Please send a '%s' request"; @@ -75,6 +75,11 @@ public class ExceptionHandling { return createHttpResponse(METHOD_NOT_ALLOWED, String.format(METHOD_IS_NOT_ALLOWED, supportedMethod)); } + @ExceptionHandler(NoHandlerFoundException.class) + public ResponseEntity noHandlerFoundException(NoHandlerFoundException exception) { + return createHttpResponse(BAD_REQUEST, "This page was not found"); + } + @ExceptionHandler(Exception.class) public ResponseEntity internalServerErrorException(Exception exception) { log.error(exception.getMessage()); diff --git a/support-portal-backend/src/main/resources/application.yml b/support-portal-backend/src/main/resources/application.yml index d06f313..d7775b6 100644 --- a/support-portal-backend/src/main/resources/application.yml +++ b/support-portal-backend/src/main/resources/application.yml @@ -10,6 +10,11 @@ spring: properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect + mvc: + throw-exception-if-no-handler-found: true + web: + resources: + add-mappings: false app: public-urls: /user/login,/user/register,/user/image/** jwt: