def from_map!(map) when is_map(map) do
try do
%Phoenix.Socket.Message{
topic: Map.fetch!(map, "topic"),
event: Map.fetch!(map, "event"),
payload: Map.fetch!(map, "payload"),
ref: Map.fetch!(map, "ref"),
join_ref: Map.get(map, "join_ref"),
}
rescue
err in [KeyError] ->
raise Phoenix.Socket.InvalidMessageError, "missing key #{inspect err.key}"
end
end
end
Ok, so it is failing to get a key with Map.fetch! .. and the error tells us which one: topic. So every message you send needs to contain the topic it relates to.
This is usually accomplished on the client side by using channel.push(), where channel comes from socket.channel(topic, params) .. if the channel is not given a topic, if the message is being sent “manually” across the socket, or is being formulated incorrectly by the underlying library in use, then you can end up without a topic key and things will go boom if a message is sent to the socket without that data …
.. so, hard to say without seeing the client side code, but hopefully that gets you started?
Thanks @aseigo, yes, at least I know that its a problem related to the client side, but, can’t I configure phoenix to tell more details about the error? like for example, what was the content of the message sent?