(KeyError) key :id not found

Hi,
Im new to Elixir how to I have to Structure my Object in JS so this method doesnt fail?

def track_user_join(socket, user) do
    track(socket, user.id, %{
      user_id: user.id,
      name: user.name,
      points: user.points,
      active: false,
    })
  end
[error] GenServer #PID<0.471.0> terminating
** (KeyError) key :id not found in: %{"active" => "false", "id" => "890", "name" => "runkunkun", "points" => "0"}

Your user uses string keys, not atoms so you save to either pattern match in the function head (%{"id" => to id} = user}) or use the Access protocol to access the id (user["id"]).

4 Likes