Skip to content

Commit 51592fb

Browse files
committed
Fix tests
1 parent a0d7f15 commit 51592fb

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/subscriptions.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ function open_subscription(fn::Function,
105105
"payload" => payload
106106
)
107107
message_str = JSON3.write(message)
108-
109-
HTTP.WebSockets.open(client.ws_endpoint; retry=retry, headers=client.headers) do ws
108+
throw_if_assigned = Ref{GraphQLClientException}()
109+
HTTP.WebSockets.open(client.ws_endpoint; retry=retry, headers=client.headers, suppress_close_error=false) do ws
110110
# Start sub
111111
output_info(verbose) && println("Starting $(get_name(subscription_name)) subscription with ID $sub_id")
112112
writews(ws, message_str)
@@ -132,11 +132,13 @@ function open_subscription(fn::Function,
132132
output_info(verbose) && println("Subscription $sub_id stopped by the stop function supplied")
133133
break
134134
end
135-
response = JSON3.read(data::Vector{UInt8}, GQLSubscriptionResponse{output_type})
135+
# Dropping typeassert as this may be string
136+
response = JSON3.read(data, GQLSubscriptionResponse{output_type})
136137
payload = response.payload
137138
if !isnothing(payload.errors) && !isempty(payload.errors) && throw_on_execution_error
138139
subscription_tracker[][sub_id] = "errored"
139-
throw(GraphQLError("Error during subscription.", payload))
140+
throw_if_assigned[] = GraphQLError("Error during subscription.", payload)
141+
break
140142
end
141143
# Handle multiple subs, do we need this?
142144
if response.id == string(sub_id)
@@ -149,6 +151,8 @@ function open_subscription(fn::Function,
149151
end
150152
end
151153
end
154+
# We can't throw errors from the ws handle function in HTTP 1.0, as they get digested.
155+
isassigned(throw_if_assigned) && throw(throw_if_assigned[])
152156
output_debug(verbose) && println("Finished. Closing subscription")
153157
subscription_tracker[][sub_id] = "closed"
154158
return

test/subscriptions.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ end
145145
output_fields="field",
146146
subtimeout=0.1)
147147
@test val[] == 2
148-
#=
148+
149149
# Error response - not throwing
150150
port = 8093
151151
send_error_localhost("This failed", port)
@@ -205,5 +205,5 @@ end
205205
@test results[1] isa GraphQLClient.GQLResponse{Response}
206206
@test isnothing(results[1].errors)
207207
@test !isnothing(results[1].data) # No point testing content as we've coded it in the test function
208-
=#
208+
209209
end

0 commit comments

Comments
 (0)