Skip to content

Commit 6378769

Browse files
committed
Removed Jason decoding exception
1 parent a5a3657 commit 6378769

File tree

2 files changed

+19
-38
lines changed

2 files changed

+19
-38
lines changed

apps/deployer/lib/deployer/github/release.ex

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,25 @@ defmodule Deployer.Github.Release do
6262
|> Finch.build(@deployex_latest_tag, [], [])
6363
|> Finch.request(Deployer.Finch)
6464

65-
case response do
66-
{:ok, %{body: body}} ->
67-
info = Jason.decode!(body)
68-
69-
tag_name = info["tag_name"]
70-
prerelease = info["prerelease"]
71-
current_version = Application.spec(:foundation, :vsn) |> to_string
72-
73-
new_release? =
74-
tag_name != nil and prerelease == false and new_release?(current_version, tag_name)
75-
76-
%__MODULE__{
77-
tag_name: tag_name,
78-
prerelease: prerelease,
79-
new_release?: new_release?,
80-
created_at: info["created_at"],
81-
updated_at: info["updated_at"],
82-
published_at: info["published_at"]
83-
}
84-
85-
{:error, _reason} ->
65+
with {:ok, %{body: body}} <- response,
66+
{:ok, info} <- Jason.decode(body) do
67+
tag_name = info["tag_name"]
68+
prerelease = info["prerelease"]
69+
current_version = Application.spec(:foundation, :vsn) |> to_string
70+
71+
new_release? =
72+
tag_name != nil and prerelease == false and new_release?(current_version, tag_name)
73+
74+
%__MODULE__{
75+
tag_name: tag_name,
76+
prerelease: prerelease,
77+
new_release?: new_release?,
78+
created_at: info["created_at"],
79+
updated_at: info["updated_at"],
80+
published_at: info["published_at"]
81+
}
82+
else
83+
_any ->
8684
# NOTE: Keep the latest state, since the application may not have acceess to
8785
# network or GitHub is not available
8886
state

apps/deployer/test/github_test.exs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,6 @@ defmodule Deployer.GithubTest do
163163
end
164164
end
165165

166-
test "handles invalid JSON response" do
167-
previous_state = %Release{tag_name: "1.0.0"}
168-
169-
with_mock Finch, [:passthrough],
170-
request: fn %Finch.Request{
171-
host: "api.github.com",
172-
path: "/repos/thiagoesteves/deployex/releases/latest"
173-
},
174-
_module ->
175-
{:ok, %{body: "invalid json {"}}
176-
end do
177-
assert_raise Jason.DecodeError, fn ->
178-
Release.update_github_info(previous_state)
179-
end
180-
end
181-
end
182-
183166
# Helper functions
184167
defp build_mock_response(overrides \\ %{}) do
185168
Map.merge(

0 commit comments

Comments
 (0)