【发布时间】:2020-04-25 10:05:25
【问题描述】:
我正在使用带有 Kotlin 协程的 Retrofit 2.7.1。
我有这样定义的改造服务:
@PUT("/users/{userId}.json")
suspend fun updateUserProfile(
@Path("userId") userId: String,
@Query("display_name") displayName: String) : Void
此调用返回 HTTP 204 No Content 响应,这会导致 Retrofit 崩溃:
kotlin.KotlinNullPointerException: Response from com.philsoft.test.api.UserApiService.updateUserProfile was null but response body type was declared as non-null
at retrofit2.KotlinExtensions$await$2$2.onResponse(KotlinExtensions.kt:43)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:129)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
如何在改造中使用协程处理 204 响应而不崩溃?
【问题讨论】:
标签: android retrofit retrofit2 kotlin-coroutines