you have to modified you function signaure from T to Nullable T? then return Resource.success(null) instead of throwing error you can modified function like below:
inline fun <reified T> Response<T?>.mapToResource(): Resource<T?> {
return if (this.isSuccessful) {
Resource.Success(this.body()) // Returns null if the body is empty
} else {
Log.e("Resource", this.message())
Resource.Error(this.message())
}
}