Skip to content

Commit

Permalink
Fix dialyzer and credo
Browse files Browse the repository at this point in the history
Signed-off-by: Connor Rigby <[email protected]>
  • Loading branch information
ConnorRigby authored and fhunleth committed Jun 17, 2024
1 parent c60fce3 commit 1ba959f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
10 changes: 4 additions & 6 deletions lib/vintage_net/connectivity/web_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,17 @@ defmodule VintageNet.Connectivity.WebRequest do

@impl VintageNet.Connectivity.Check
def check(ifname, {__MODULE__, options}) do
with {:ok, body} <- make_request(ifname, options) do
evaluate_match(body, options[:match])
else
case make_request(ifname, options) do
{:ok, body} ->
evaluate_match(body, options[:match])

{:error, :econnrefused} ->
# If the remote refuses the connection, then that means that someone
# received it and we're connected at least connected to a LAN!
{:ok, {:lan, []}}

{:error, reason} ->
{:error, reason}

posix_error when is_atom(posix_error) ->
{:error, posix_error}
end
end

Expand Down
10 changes: 6 additions & 4 deletions lib/vintage_net/connectivity/when_where.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ defmodule VintageNet.Connectivity.WhenWhere do

{:error, reason} ->
{:error, reason}

posix_error when is_atom(posix_error) ->
{:error, posix_error}
end
end

@spec make_request(VintageNet.ifname(), String.t(), Keyword.t()) ::
{:ok, [{String.t(), String.t()}], map()} | {:error, term()}
{:ok, [{String.t(), String.t()}], map()}
| {:error, 400..599, String.t()}
| {:error, term()}
defp make_request(ifname, nonce, options) do
url = %{options[:url] | query: "nonce=#{nonce}"}
request_headers = [{"Content-Type", "application/x-erlang-binary"}]
Expand All @@ -79,6 +78,9 @@ defmodule VintageNet.Connectivity.WhenWhere do
{:ok, {{_version, 200, _status_message}, headers, body}} ->
{:ok, headers, :erlang.binary_to_term(body, [:safe])}

{:ok, {{_version, status_code, _status_message}, _headers, body}} ->
{:error, status_code, body}

error ->
error
end
Expand Down
7 changes: 1 addition & 6 deletions test/vintage_net/connectivity/when_where_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ defmodule VintageNet.Connectivity.WhenWhereTest do

@properties [
["address"],
["city"],
["country"],
["country_region"],
["latitude"],
["longitude"],
["now"],
["time_zone"]
["now"]
]

# If this fails it may be because whenwhere is down or doesn't support your network.
Expand Down

0 comments on commit 1ba959f

Please sign in to comment.