I am facing a "problem" with mongo reactive repositories. I am trying to use kotlin's coroutines and instead of writing fun declaration like this:
fun findEntityById(id: String) : Mono<Entity>
I wrote a suspend function like this :
suspend fun findEntityById(id: String) : Entity
But when I test the function with an id that does not exist, instead of getting an DataAccessException(what I anticipated), I am getting null. Is there a way to "fix" this or get around. For now I only thought of something like this
suspend fun findEntityById(id: String) : Entity = findEntityById(id).awaitSingleOrNull() ?: throw EmptyResultDataAccessException()
Maybe there is a better solution and someone has faced the same "problem" that I have(or maybe I am doing something wrong), i'd be glad to hear any suggestions.