Skip to content

Commit

Permalink
fix: declarative client with suspended function fails on 404 (#5575)
Browse files Browse the repository at this point in the history
* fix: declarative client with suspended function fails on 404

* fix: add tests for nullable return types

* PR feedback
  • Loading branch information
wlezzar committed Jun 14, 2021
1 parent f01d96d commit 5ef638a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,8 @@ public Object handleResult(Object result) {
}
completionStageResult.whenComplete((value, throwable) -> {
if (throwable == null) {
if (value == null) {
if (isUnitValueType) {
value = kotlin.Unit.INSTANCE;
} else {
CompletableFutureContinuation.Companion.completeExceptionally(continuation, new IllegalStateException("Cannot complete Kotlin coroutine with null: " + returnTypeValue.getType()));
return;
}
if (value == null && isUnitValueType) {
value = kotlin.Unit.INSTANCE;
}
CompletableFutureContinuation.Companion.completeSuccess(continuation, value);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ interface SuspendClient {

@Get
suspend fun notFound(): HttpResponse<String?>

@Get
suspend fun notFoundWithoutHttpResponseWrapper(): String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ class SuspendClientSpec {

Assertions.assertEquals(response.status, HttpStatus.NOT_FOUND)
}

@Test
fun testNotFoundWithoutHttpResponseWrapper() {
val server = ApplicationContext.run(EmbeddedServer::class.java, mapOf("spec.name" to "SuspendClientSpec"))
val ctx = server.applicationContext
val response = runBlocking {
ctx.getBean(SuspendClient::class.java).notFoundWithoutHttpResponseWrapper()
}

Assertions.assertNull(response)
}

}

0 comments on commit 5ef638a

Please sign in to comment.