Cies
06/11/2024, 4:27 PMif (rank == null) return BadRequest("Rank is missing")
or rank ?: return BadRequest("Rank is missing")
?Klitos Kyriacou
06/11/2024, 4:29 PMrank
.dmays
06/11/2024, 10:25 PMRohde Fischer
06/12/2024, 6:26 PMnull
to begin with, but rather to model the domain, so domain errors are communicated nicely, using the Either-monad
i.e.:
sealed interface RankError
data class RankMissingError(val rankId: RankId): RankError
fun getRank(rankId: RankId): Either<RankError, Rank>
that way the model communicates your domain in a clear and consistent way, one starts adding relevant metadata (such as the rank id to the error), it's expandable, without implicit and inconsistent definitions of null
in general null
is still an anti pattern, if for no other reason than DDD, null
is not a domain term in most domains, in those where it is it is almost never the same as the computer science definition