elixir - Ecto变更集成功和失败代码不再运行

问题描述 投票:0回答:1

此代码用于向messages变量添加字符串,然后在http响应中将它们发回。现在没有任何东西被添加到messages变量中。 :ok和:error块内的代码行不再运行。我现在应该在哪里处理错误和成功案例,在错误和成功时添加消息?

  messages = {}

  changeset = Api.UserProduct.changeset(
    user_product, %{:voted_vegan => true}
  )

  case Api.Repo.update(changeset) do
      {:ok, product} -> 
        IO.puts("appending messages7")
        messages = Tuple.append(messages, "Product updated")
      {:error, changeset} -> 
        IO.puts("appending messages8")
        messages = Tuple.append(messages, "Product not updated")
  end

  conn
      |> put_resp_content_type("application/json")
      |> send_resp(200, Poison.encode!(%{
          successs: "success",
          errors: Tuple.to_list(messages)
      }))
elixir ecto
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.