throwNotFoundIfEmpty

fun <T> Mono<T>.throwNotFoundIfEmpty(errorMsg: String = ErrorCodes.NOT_FOUND_MESSAGE, cause: Throwable? = null): Mono<T>

Throws NotFoundResourceException if the Mono is empty.

This extension function converts an empty Mono into an error signal containing a NotFoundResourceException. It's useful for handling cases where a resource lookup returns no results.

Example usage:

val resource = repository.findById(id)
.throwNotFoundIfEmpty("Resource with ID $id not found")

Return

a Mono that signals NotFoundResourceException if empty

Parameters

errorMsg

the error message for the exception

cause

the underlying cause, if any


fun <T> Flux<T>.throwNotFoundIfEmpty(errorMsg: String = ErrorCodes.NOT_FOUND_MESSAGE, cause: Throwable? = null): Flux<T>

Throws NotFoundResourceException if the Flux is empty.

This extension function converts an empty Flux into an error signal containing a NotFoundResourceException. It's useful for handling cases where a collection lookup returns no results.

Example usage:

val resources = repository.findAll()
.throwNotFoundIfEmpty("No resources found")

Return

a Flux that signals NotFoundResourceException if empty

Parameters

errorMsg

the error message for the exception

cause

the underlying cause, if any