Skip to content

Commit

Permalink
treat no streams as an empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmries committed Apr 17, 2024
1 parent 353b7bf commit 68d368b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/gnat/jetstream/api/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,18 @@ defmodule Gnat.Jetstream.API.Stream do
})

with {:ok, decoded} <- request(conn, "#{js_api(domain)}.STREAM.NAMES", payload) do
# Recent versions of NATS sometimes return `"streams": null` in their JSON payload to indicate
# that no streams are defined. But, that would mean callers have to handle both `nil` and a list, so
# we coerce that to an empty list to represent no streams being defined.
streams = case Map.get(decoded, "streams") do
nil -> []
names when is_list(names) -> names
end

result = %{
limit: Map.get(decoded, "limit"),
offset: Map.get(decoded, "offset"),
streams: Map.get(decoded, "streams"),
streams: streams,
total: Map.get(decoded, "total")
}

Expand Down

0 comments on commit 68d368b

Please sign in to comment.