aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-09-10 18:40:54 +0000
committerrinpatch <rinpatch@sdf.org>2020-09-10 18:40:54 +0000
commit53cf7fef6ec097d60b73ef3ad6771fed7c83ff48 (patch)
tree349d781b79455cc615710c9d35bdd8aebf049e83 /lib
parent45c299e5b52e2324486d42d53543dbf1f5c02b7b (diff)
parent275602daa7c4a01dffb83759012554da2d9335fe (diff)
downloadpleroma-53cf7fef6ec097d60b73ef3ad6771fed7c83ff48.tar.gz
Merge branch 'fix/streaming-termination-errors' into 'develop'
Fix two pseudo-errors in websocket handler Closes #2131 See merge request pleroma/pleroma!2982
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/websocket_handler.ex12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/pleroma/web/mastodon_api/websocket_handler.ex b/lib/pleroma/web/mastodon_api/websocket_handler.ex
index 94e4595d8..cf923ded8 100644
--- a/lib/pleroma/web/mastodon_api/websocket_handler.ex
+++ b/lib/pleroma/web/mastodon_api/websocket_handler.ex
@@ -37,12 +37,12 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
else
{:error, :bad_topic} ->
Logger.debug("#{__MODULE__} bad topic #{inspect(req)}")
- {:ok, req} = :cowboy_req.reply(404, req)
+ req = :cowboy_req.reply(404, req)
{:ok, req, state}
{:error, :unauthorized} ->
Logger.debug("#{__MODULE__} authentication error: #{inspect(req)}")
- {:ok, req} = :cowboy_req.reply(401, req)
+ req = :cowboy_req.reply(401, req)
{:ok, req, state}
end
end
@@ -64,7 +64,9 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
{:ok, %{state | timer: timer()}}
end
- # We never receive messages.
+ # We only receive pings for now
+ def websocket_handle(:ping, state), do: {:ok, state}
+
def websocket_handle(frame, state) do
Logger.error("#{__MODULE__} received frame: #{inspect(frame)}")
{:ok, state}
@@ -98,6 +100,10 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
{:reply, :ping, %{state | timer: nil, count: 0}, :hibernate}
end
+ # State can be `[]` only in case we terminate before switching to websocket,
+ # we already log errors for these cases in `init/1`, so just do nothing here
+ def terminate(_reason, _req, []), do: :ok
+
def terminate(reason, _req, state) do
Logger.debug(
"#{__MODULE__} terminating websocket connection for user #{