@@ -51,16 +51,19 @@ websocket_handle({text, Text}, State = #{authenticated := true,
51
51
peer_id := ThisPeer }) ->
52
52
lager :debug (" Received text frame ~p " , [Text ]),
53
53
54
- % % TODO reply error if `to` is missing
55
- Message = #{to := OtherPeer } = json_decode (Text ),
56
- % % crash if room doesn't match
57
- {Pid , {_Username , _PeerId , Room }} = syn :find_by_key (OtherPeer , with_meta ),
58
-
59
- % % extend message with this peer id before sending
60
- Message2 = Message #{from => ThisPeer },
61
- Pid ! {text , json_encode (Message2 )},
62
-
63
- {ok , State };
54
+ case json_decode (Text ) of
55
+ #{to := OtherPeer } = Message ->
56
+ % % crash if room doesn't match
57
+ {Pid , {_Username , _PeerId , Room }} = syn :find_by_key (OtherPeer , with_meta ),
58
+
59
+ % % extend message with this peer id before sending
60
+ Message2 = Message #{from => ThisPeer },
61
+ Pid ! {text , json_encode (Message2 )},
62
+
63
+ {ok , State };
64
+ _ ->
65
+ {reply , reply_text (invalid_message ), State }
66
+ end ;
64
67
65
68
websocket_handle (Frame , State ) ->
66
69
lager :warning (" Received non text frame ~p~p " , [Frame , State ]),
0 commit comments