mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-24 06:48:07 +08:00
Make send/recv websocket responses consistent
This commit is contained in:
parent
6bd7bbd1fc
commit
d6848ed106
2 changed files with 7 additions and 7 deletions
|
@ -97,7 +97,7 @@ defmodule Livebook.Teams.Connection do
|
|||
|
||||
{:keep_state, data}
|
||||
|
||||
{:server_error, conn, websocket, reason} ->
|
||||
{:error, conn, websocket, reason} ->
|
||||
send(data.listener, {:connection_error, reason})
|
||||
data = %__MODULE__{data | http_conn: conn, websocket: websocket}
|
||||
|
||||
|
|
|
@ -118,15 +118,15 @@ defmodule Livebook.Teams.WebSocket do
|
|||
"""
|
||||
@spec disconnect(conn(), websocket() | nil, ref()) ::
|
||||
{:ok, conn(), websocket() | nil}
|
||||
| {:error, conn() | websocket(), term()}
|
||||
| {:error, conn(), websocket(), term()}
|
||||
def disconnect(conn, nil, _ref) do
|
||||
{:ok, conn} = Mint.HTTP.close(conn)
|
||||
{:ok, conn, nil}
|
||||
end
|
||||
|
||||
def disconnect(conn, websocket, ref) do
|
||||
with {:ok, conn, websocket} <- send(conn, websocket, ref, :close),
|
||||
{:ok, conn} <- Mint.HTTP.close(conn) do
|
||||
with {:ok, conn, websocket} <- send(conn, websocket, ref, :close) do
|
||||
{:ok, conn} = Mint.HTTP.close(conn)
|
||||
{:ok, conn, websocket}
|
||||
end
|
||||
end
|
||||
|
@ -139,7 +139,7 @@ defmodule Livebook.Teams.WebSocket do
|
|||
"""
|
||||
@spec receive(conn(), ref(), websocket(), term()) ::
|
||||
{:ok, conn(), websocket(), list(binary())}
|
||||
| {:server_error, conn(), websocket(), String.t()}
|
||||
| {:error, conn(), websocket(), String.t()}
|
||||
def receive(conn, ref, websocket, message \\ receive(do: (message -> message))) do
|
||||
with {:ok, conn, [{:data, ^ref, data}]} <- Mint.WebSocket.stream(conn, message),
|
||||
{:ok, websocket, frames} <- Mint.WebSocket.decode(websocket, data),
|
||||
|
@ -150,10 +150,10 @@ defmodule Livebook.Teams.WebSocket do
|
|||
handle_disconnect(conn, websocket, ref, response)
|
||||
|
||||
{:error, conn, exception} when is_exception(exception) ->
|
||||
{:server_error, conn, websocket, Exception.message(exception)}
|
||||
{:error, conn, websocket, Exception.message(exception)}
|
||||
|
||||
{:error, conn, exception, []} when is_exception(exception) ->
|
||||
{:server_error, conn, websocket, Exception.message(exception)}
|
||||
{:error, conn, websocket, Exception.message(exception)}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue