Skip to content

Commit

Permalink
fix: Websocket error broadcast for unsubscribed ID (apollographql/apo…
Browse files Browse the repository at this point in the history
  • Loading branch information
calvincestari authored and gh-action-runner committed Oct 16, 2024
1 parent bc5a0cd commit 9d8aafb
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Sources/ApolloWebSocket/WebSocketTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,21 @@ public class WebSocketTransport {
}

switch messageType {
case .data,
.next,
.error:
if let id = parseHandler.id, let responseHandler = subscribers[id] {
case .data, .next, .error:
guard let id = parseHandler.id else {
let websocketError = WebSocketError(
payload: parseHandler.payload,
error: parseHandler.error,
kind: .unprocessedMessage(text)
)
self.notifyErrorAllHandlers(websocketError)

break
}

// If we have a handler ID but no subscriber exists for that ID then the
// subscriber probably unsubscribed.
if let responseHandler = subscribers[id] {
if let payload = parseHandler.payload {
responseHandler(.success(payload))
} else if let error = parseHandler.error {
Expand All @@ -207,11 +218,6 @@ public class WebSocketTransport {
kind: .neitherErrorNorPayloadReceived)
responseHandler(.failure(websocketError))
}
} else {
let websocketError = WebSocketError(payload: parseHandler.payload,
error: parseHandler.error,
kind: .unprocessedMessage(text))
self.notifyErrorAllHandlers(websocketError)
}
case .complete:
if let id = parseHandler.id {
Expand Down

0 comments on commit 9d8aafb

Please sign in to comment.