Skip to content

Commit d362ac9

Browse files
committed
Fix demo to handle variants
1 parent ab885d0 commit d362ac9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

examples/feature_flag_demo/lib/feature_flag_demo.ex

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ defmodule FeatureFlagDemo do
7676
{:ok, %{enabled: false}} ->
7777
IO.puts("Feature flag '#{flag}' is DISABLED")
7878

79+
{:ok, %{enabled: variant, payload: payload}} when is_binary(variant) ->
80+
IO.puts("Feature flag '#{flag}' is ENABLED with variant: #{variant}")
81+
if payload, do: IO.puts("Payload: #{inspect(payload)}")
82+
7983
{:error, %{status: 403}} ->
8084
IO.puts("""
8185
Error: Authentication failed (403 Forbidden)
@@ -98,15 +102,12 @@ defmodule FeatureFlagDemo do
98102
""")
99103

100104
{:error, reason} ->
101-
IO.puts("Error checking feature flag: #{inspect(reason)}")
105+
IO.puts("Error: #{inspect(reason)}")
102106
end
103107
end
104108

105-
defp parse_json(nil), do: %{}
106-
defp parse_json(json) when is_binary(json) do
107-
case Jason.decode(json) do
108-
{:ok, result} -> result
109-
{:error, _} -> %{}
110-
end
111-
end
109+
defp parse_json(nil), do: nil
110+
defp parse_json(""), do: nil
111+
defp parse_json(json) when is_binary(json), do: Jason.decode!(json)
112+
defp parse_json(value), do: value
112113
end

0 commit comments

Comments
 (0)