You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting up Locations to convert a parameter to an Enum, as follows:
enum class State{
ACTIVE,
UNKNOWN
}
object Paths {
@Location("/") class getBase(val `state`: List<State>? = null)
}
If request contains a value not in the Enum e.g. /?state=NO, or is empty /?state= then DefaultConversionService throws a NoSuchElementException because the call type.enumConstants.first fails to find a value.
Since the state is nullable it would be good if it could return null in the empty case. In the case of a wrong value it would be helpful if the generic NoSuchElementException could be wrapped in a DataConversionException which could be caught and return 400. A NoSuchElementException could have a variety of causes and would be a very generic catch.
The text was updated successfully, but these errors were encountered:
lupiter
changed the title
ConversionService throws confusing NoSuchElementException when converting invalid Enums
DefaultConversionService throws confusing NoSuchElementException when converting invalid Enums
May 10, 2018
Setting up Locations to convert a parameter to an Enum, as follows:
If request contains a value not in the Enum e.g.
/?state=NO
, or is empty/?state=
then DefaultConversionService throws a NoSuchElementException because the calltype.enumConstants.first
fails to find a value.Since the state is nullable it would be good if it could return null in the empty case. In the case of a wrong value it would be helpful if the generic NoSuchElementException could be wrapped in a DataConversionException which could be caught and return 400. A NoSuchElementException could have a variety of causes and would be a very generic catch.
The text was updated successfully, but these errors were encountered: