title: Elixir UUID. How to handle 500 error when UUID doesn't match
body: <pre><code>def show(conn, %{"id" =&gt; id}) do
    with {:ok, user} &lt;- UserAction.get_user(id)
      |&gt; put_status(200)
      |&gt; render("show.json", %{user: user})
    else
      {:error, :not_found} -&gt; {:error, :not_found, %User{id: id}}
    end
  end
  </code></pre>
  
  <p>When id is invalid, <code>Ecto</code> raises:</p>
  
  <pre><code>Ecto.Query.CastError - cannot be dumped to type :binary_id in query. 
  </code></pre>
  
  <p>My <code>get_user</code> function: </p>
  
  <pre><code>query = from(u in User, where u.id == ^id)
  
  case Repo.all(query) do
    [%User{} = user] -&gt; {:ok, user}
    _ -&gt; {:error, :not_found}
  end
  </code></pre>
  
  <p>Is there any convenient way for handling this error to prevent 500 responses?</p>