From 6a1a5301b75872ccffe9c60c5290c447bcb8abd8 Mon Sep 17 00:00:00 2001 From: Art Date: Tue, 28 Sep 2021 10:01:23 +0300 Subject: [PATCH] #39 fix issue /user/image/1 - produces 404 without appropriate HttpResponse message --- .../backend/exception/ExceptionHandling.java | 9 +++++---- .../src/main/resources/application.yml | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) 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 55c66da..041f597 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 @@ -16,6 +16,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.multipart.MaxUploadSizeExceededException; +import org.springframework.web.servlet.NoHandlerFoundException; import javax.persistence.NoResultException; import java.io.IOException; @@ -83,10 +84,10 @@ 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(NoHandlerFoundException.class) + public ResponseEntity noHandlerFoundException(NoHandlerFoundException exception) { + return createHttpResponse(NOT_FOUND, "Resource not found"); + } @ExceptionHandler(Exception.class) public ResponseEntity internalServerErrorException(Exception exception) { diff --git a/support-portal-backend/src/main/resources/application.yml b/support-portal-backend/src/main/resources/application.yml index ed9929f..8468af3 100644 --- a/support-portal-backend/src/main/resources/application.yml +++ b/support-portal-backend/src/main/resources/application.yml @@ -34,11 +34,11 @@ spring: max-file-size: 10MB max-request-size: 100MB -# mvc: -# throw-exception-if-no-handler-found: true -# web: -# resources: -# add-mappings: false + mvc: + throw-exception-if-no-handler-found: true + web: + resources: + add-mappings: false app: public-urls: /user/login,/user/register,/user/*/image/**,/user/image/** cors: