From 13fd9d89632b5fea2779297d7746bc6bfab46bc0 Mon Sep 17 00:00:00 2001 From: Jan Cizmar Date: Mon, 23 Sep 2024 10:41:35 +0200 Subject: [PATCH] fix: No static resource found error handling --- .../main/kotlin/io/tolgee/ExceptionHandlers.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/app/src/main/kotlin/io/tolgee/ExceptionHandlers.kt b/backend/app/src/main/kotlin/io/tolgee/ExceptionHandlers.kt index 4f21919c7a..3f16f427a2 100644 --- a/backend/app/src/main/kotlin/io/tolgee/ExceptionHandlers.kt +++ b/backend/app/src/main/kotlin/io/tolgee/ExceptionHandlers.kt @@ -7,7 +7,11 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse import io.tolgee.constants.Message import io.tolgee.dtos.request.validators.ValidationErrorType import io.tolgee.dtos.request.validators.exceptions.ValidationException -import io.tolgee.exceptions.* +import io.tolgee.exceptions.BadRequestException +import io.tolgee.exceptions.ErrorException +import io.tolgee.exceptions.ErrorResponseBody +import io.tolgee.exceptions.ErrorResponseTyped +import io.tolgee.exceptions.NotFoundException import io.tolgee.security.ratelimit.RateLimitResponseBody import io.tolgee.security.ratelimit.RateLimitedException import jakarta.persistence.EntityNotFoundException @@ -32,6 +36,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException import org.springframework.web.multipart.MaxUploadSizeExceededException import org.springframework.web.multipart.support.MissingServletRequestPartException +import org.springframework.web.servlet.resource.NoResourceFoundException import java.io.Serializable import java.util.* import java.util.function.Consumer @@ -238,6 +243,15 @@ class ExceptionHandlers { ) } + @ExceptionHandler(NoResourceFoundException::class) + fun handleNoResourceFound(ex: NoResourceFoundException): ResponseEntity { + logger.debug("No resource found", ex) + return ResponseEntity( + ErrorResponseBody(Message.RESOURCE_NOT_FOUND.code, listOf(ex.resourcePath)), + HttpStatus.NOT_FOUND, + ) + } + @ExceptionHandler(Throwable::class) fun handleOtherExceptions(ex: Throwable): ResponseEntity { Sentry.captureException(ex)