Retrofit - delete was null but response body type was declared as non-null

Viewed 2038

So, After I delete a specific topic in my API it throws to me this error message

deleteTopic was null but response body type was declared as non-null

The topic is succefully deleted but in my client, this response resolves in my catch block somehow

Service

@DELETE("topics/{id}")
    suspend fun deleteTopic(@Path("id") id:String)

Repo

override suspend fun deleteTopic(id: String): Resource<Unit> {
        return Resource.Success(RetrofitClient.webservice.deleteTopic(id))
    }

ViewModel

fun deleteTopic(id:String) = liveData(Dispatchers.IO) {
        emit(Resource.Loading())
        try {
            emit(repo.deleteTopic(id))
        }catch (e:Exception){
            emit(Resource.Failure(e))
        }
    }

For some reason I succefully delete the topic in my server, but when it returns to my client, it goes to the catch and returns this exception that I mentioned above, the response is a 204 not content, but how can I fix this response to sucefully tell me that this operation has done correctly ?

I'm confused, I have readed into github that I must retunr Response<Unit> but I'm still confused why I should do this, it also says taht returning that will prevent my 4xx return codes to be thrown

2 Answers
Related