In my controller I have:
@Get("/{id}")
fun findById(id: String): Maybe<AccountTransaction> {
return accountTransactionRepository.findById(ObjectId(id))
}
The repository looks like:
fun findById(id: ObjectId): Maybe<AccountTransaction> {
return Flowable.fromPublisher(getCollection().find(Filters.eq("_id", id))).firstElement()
}
If I pass in an invalid ID, the controller responds correctly with a 404. That's great! I just don't know why / how that is happening. I assume that's just baked in to MN and it checks to see if it is empty or not. But can someone explain that to me / confirm?
I assume that's just baked in to MN and it checks to see if it is empty or not. But can someone explain that to me / confirm?
A 404 is generated any time a controller action returns null or an empty Maybe
.
More info is available at https://docs.micronaut.io/2.4.2/guide/#serverIO.