throwNotFoundIfNull

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

Throws NotFoundResourceException if the value is null.

This extension function checks if the receiver is null and throws a NotFoundResourceException if it is. Otherwise, it returns the non-null value.

Example usage:

val resource = findResource(id).throwNotFoundIfNull("Resource $id not found")
// resource is guaranteed to be non-null here

Return

the non-null value

Parameters

errorMsg

the error message for the exception

cause

the underlying cause, if any

Throws

if the value is null