gpt4 book ai didi

android - retrofit - 删除为空但响应主体类型被声明为非空

转载 作者:行者123 更新时间:2023-12-05 00:19:24 24 4
gpt4 key购买 nike

因此,在我删除 API 中的特定主题后,它会向我抛出此错误消息

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

主题已成功删除,但在我的客户端中,此响应以某种方式在我的 catch block 中解析

服务

@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))
}

View 模型

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

出于某种原因,我成功地删除了我的服务器中的主题,但是当它返回到我的客户端时,它进入捕获并返回我上面提到的这个异常,响应是 204 not content,但我该如何修复此响应成功地告诉我此操作已正确完成?

我很困惑,我已经在 github 上读到我必须返回 Response<Unit>但我仍然很困惑为什么我应该这样做,它还说 taht return that will prevent my 4xx return codes to be thrown

最佳答案

关于android - retrofit - 删除为空但响应主体类型被声明为非空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63040817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com