Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: No static resource found error handling #2479

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading