Skip to content

Commit f61dfc5

Browse files
committed
Align future handling with AsyncServerResponse
See gh-959
1 parent 21a7c81 commit f61dfc5

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandler.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.concurrent.CompletableFuture;
2222
import java.util.concurrent.ExecutionException;
2323

24-
import jakarta.servlet.ServletException;
2524
import reactor.core.publisher.Mono;
2625

2726
import org.springframework.graphql.server.WebGraphQlHandler;
@@ -70,8 +69,7 @@ public GraphQlHttpHandler(WebGraphQlHandler graphQlHandler, @Nullable HttpMessag
7069

7170

7271
@Override
73-
protected ServerResponse prepareResponse(ServerRequest request, Mono<WebGraphQlResponse> responseMono)
74-
throws ServletException {
72+
protected ServerResponse prepareResponse(ServerRequest request, Mono<WebGraphQlResponse> responseMono) {
7573

7674
CompletableFuture<ServerResponse> future = responseMono.map((response) -> {
7775
MediaType contentType = selectResponseMediaType(request);
@@ -87,15 +85,15 @@ protected ServerResponse prepareResponse(ServerRequest request, Mono<WebGraphQlR
8785
}
8886
}).toFuture();
8987

90-
if (future.isDone()) {
88+
// This won't be needed with a Spring Framework 6.2 baseline:
89+
// https://github.com/spring-projects/spring-framework/issues/32223
90+
91+
if (future.isDone() && !future.isCancelled() && !future.isCompletedExceptionally()) {
9192
try {
9293
return future.get();
9394
}
94-
catch (ExecutionException ex) {
95-
throw new ServletException(ex.getCause());
96-
}
97-
catch (InterruptedException ex) {
98-
throw new ServletException(ex);
95+
catch (InterruptedException | ExecutionException ignored) {
96+
// fall through to use DefaultAsyncServerResponse
9997
}
10098
}
10199

0 commit comments

Comments
 (0)