Adds file type detection, and beefs up error states for file uploads

This commit is contained in:
2026-05-14 11:13:19 -05:00
parent 5ca7a685dd
commit 1dd904055c
6 changed files with 80 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
package net.halfbinary.scavengerhuntapi.error
import net.halfbinary.scavengerhuntapi.error.exception.BadFileException
import net.halfbinary.scavengerhuntapi.error.exception.InvalidEmailException
import net.halfbinary.scavengerhuntapi.error.exception.LoginFailedException
import net.halfbinary.scavengerhuntapi.error.exception.NotFoundException
@@ -12,6 +13,8 @@ import org.springframework.web.bind.MethodArgumentNotValidException
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.multipart.MaxUploadSizeExceededException
import java.net.SocketTimeoutException
@RestControllerAdvice
@@ -68,6 +71,24 @@ class ExceptionHandler {
}
}
@ExceptionHandler(BadFileException::class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
fun badFileException(e: BadFileException): String? {
return e.message
}
@ExceptionHandler(MaxUploadSizeExceededException::class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
fun maxUploadSizeExceededException(e: MaxUploadSizeExceededException): String? {
return e.message
}
@ExceptionHandler(SocketTimeoutException::class)
@ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE)
fun socketTimeoutException(): String {
return "Unable to connect. Try again later."
}
private fun simpleMap(key: String, value: String?): Map<String, String?> {
return mapOf(Pair(key, value))
}