diff --git a/CHANGELOG.md b/CHANGELOG.md index 4179538e22..8bde64c26a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,9 @@ and this project adheres to ### Fixed +- Collections controller sending an invalid response body when a item doesn't + exist [#2733](https://github.com/OpenFn/lightning/issues/2733) + ## [v2.10.4] - 2024-11-22 ### Added diff --git a/lib/lightning_web/controllers/collections_controller.ex b/lib/lightning_web/controllers/collections_controller.ex index e528864434..4cf12dce47 100644 --- a/lib/lightning_web/controllers/collections_controller.ex +++ b/lib/lightning_web/controllers/collections_controller.ex @@ -59,9 +59,7 @@ defmodule LightningWeb.CollectionsController do :ok <- authorize(conn, collection) do case Collections.get(collection, key) do nil -> - conn - |> put_status(:no_content) - |> json(nil) + resp(conn, :no_content, "") item -> json(conn, item) diff --git a/test/lightning_web/collections_controller_test.exs b/test/lightning_web/collections_controller_test.exs index fc21a28bd1..0307797271 100644 --- a/test/lightning_web/collections_controller_test.exs +++ b/test/lightning_web/collections_controller_test.exs @@ -131,7 +131,7 @@ defmodule LightningWeb.API.CollectionsControllerTest do |> assign_bearer(token) |> get(~p"/collections/#{collection.name}/some-unexisting-key") - assert json_response(conn, 204) == nil + assert response(conn, 204) == "" end end