79475197

Date: 2025-02-28 10:24:40
Score: 0.5
Natty:
Report link

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())
        }
}
Reasons:
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: Jaspalsinh Gohil