Skip to content

Commit f5d370e

Browse files
committed
Catch any exception thrown during Apollo onConnect subscription
1 parent 7c2b3bd commit f5d370e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/java/graphql/servlet/internal/ApolloSubscriptionProtocolHandler.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ public void onMessage(HandshakeRequest request, Session session, WsSessionSubscr
5656

5757
switch(message.getType()) {
5858
case GQL_CONNECTION_INIT:
59-
Optional<Object> connectionResponse = connectionListener.onConnect(message.getPayload());
60-
connectionResponse.ifPresent(it -> session.getUserProperties().put(ApolloSubscriptionConnectionListener.CONNECT_RESULT_KEY, it));
59+
try {
60+
Optional<Object> connectionResponse = connectionListener.onConnect(message.getPayload());
61+
connectionResponse.ifPresent(it -> session.getUserProperties().put(ApolloSubscriptionConnectionListener.CONNECT_RESULT_KEY, it));
62+
} catch (Throwable t) {
63+
sendMessage(session, OperationMessage.Type.GQL_ERROR, t.getMessage());
64+
return;
65+
}
66+
6167
sendMessage(session, OperationMessage.Type.GQL_CONNECTION_ACK, message.getId());
6268

6369
if (connectionListener.isKeepAliveEnabled()) {

0 commit comments

Comments
 (0)