Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/minch/conn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ defmodule Minch.Conn do

defp handle_frame(_frame, %State{conn: nil} = state), do: {:noreply, state}

defp handle_frame({:error, reason}, %State{} = state) do
handle_error({:decode_frame, reason}, state)
end

# the server initiated close
defp handle_frame({:close, _, _} = frame, %State{close_frame: nil} = state) do
state = state |> stream_frame(frame) |> discard_error()
Expand Down
8 changes: 8 additions & 0 deletions test/minch/client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ defmodule Minch.ClientTest do
assert_receive {:client, :handle_frame, [{:pong, "123"}, _state]}
end

test "handle_error/2 is called for a frame that fails to decode", ctx do
assert_receive {:client, :handle_connect, _}
Server.send_frame(ctx.server, [{:text, <<0xFF>>}, {:text, "a"}])
assert_receive {:client, :handle_error, [{:decode_frame, {:invalid_utf8, <<0xFF>>}}, _]}
assert_receive {:client, :handle_frame, [{:text, "a"}, _state]}
refute_received {:client, :handle_frame, [{:error, _}, _state]}
end

test "handle_frame/2 is called with frames received before a close", ctx do
assert_receive {:client, :handle_connect, _}
# suspended so the frames and the socket close land in the mailbox together
Expand Down
Loading