Closed florentsorel closed 1 year ago
Sorry, I didn't get a notification about this issue. I will extend UUIDFormatException
from IllegalArgumentException
. If you don't care about the exception message, you could just use String.toUUIDOrNull()
.
I was trying to handle a bad format uuid inside a spring boot application and something seems weird to handle this case.
I have a basic controller with a
@PathVariable
annotation:When the uuid is not valid for example
/v1/actors/test
aMethodArgumentTypeMismatchException
is thrown with this error:Failed to convert value of type 'java.lang.String' to required type 'kotlinx.uuid.UUID'; Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.PathVariable kotlinx.uuid.UUID] for value [test]
So instead of handle
MethodArgumentTypeMismatchException
inside a@RestControllerAdvice
I created a converter to parse the string into an uuid with a custom exception:The thing is, I catch
Exception
here and it's handle inside myRestControllerAdvice
, if I remove the case for@ExceptionHandler(Exception::class)
my custom exception is thrown and the@ExceptionHandler(UUIDConverterException::class)
is called.UUIDFormatException
extends fromException
soonUuidConverterException
method is never called.So, it would be better if we can use
UUIDFormatException
to handle this kind of case? Or extends it fromRuntimeException
instead ofException
?