Skip to content

Commit

Permalink
Don't allow unchecked exception to propagate
Browse files Browse the repository at this point in the history
If Jackson serialization fails, a checked exception is thrown in WebsocketGraphQLWSProtocolHandler, but
the library code written in Java is written to only catch runtime exceptions; switch to throwing a
runtime exception so that the appropriate error handler is called.
  • Loading branch information
Patrick Strawderman authored and kilink committed Jan 18, 2024
1 parent 59ff638 commit 835e63f
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.graphql.dgs.subscriptions.websockets

import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.graphql.dgs.DgsQueryExecutor
import com.netflix.graphql.types.subscription.*
Expand All @@ -30,6 +31,7 @@ import org.slf4j.event.Level
import org.springframework.web.socket.TextMessage
import org.springframework.web.socket.WebSocketSession
import org.springframework.web.socket.handler.TextWebSocketHandler
import java.io.UncheckedIOException
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArrayList
Expand Down Expand Up @@ -110,7 +112,11 @@ class WebsocketGraphQLWSProtocolHandler(

override fun onNext(er: ExecutionResult) {
val message = OperationMessage(GQL_DATA, DataPayload(er.getData(), er.errors), id)
val jsonMessage = TextMessage(objectMapper.writeValueAsBytes(message))
val jsonMessage = try {
TextMessage(objectMapper.writeValueAsBytes(message))
} catch (exc: JsonProcessingException) {
throw UncheckedIOException(exc)
}
logger.debug("Sending subscription data: {}", jsonMessage)

if (session.isOpen) {
Expand Down

0 comments on commit 835e63f

Please sign in to comment.