Skip to content

Commit

Permalink
fix: No static resource found error handling (#2479)
Browse files Browse the repository at this point in the history
It was throwing 500 when static resource was not found. (Usually
favicon.ico)
  • Loading branch information
JanCizmar committed Sep 23, 2024
1 parent 9c56a17 commit cadcfa4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion backend/app/src/main/kotlin/io/tolgee/ExceptionHandlers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -238,6 +243,15 @@ class ExceptionHandlers {
)
}

@ExceptionHandler(NoResourceFoundException::class)
fun handleNoResourceFound(ex: NoResourceFoundException): ResponseEntity<ErrorResponseBody> {
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<ErrorResponseBody> {
Sentry.captureException(ex)
Expand Down

0 comments on commit cadcfa4

Please sign in to comment.