From 1ba959f25ff0f3edfd4a1106cac90a9885312148 Mon Sep 17 00:00:00 2001 From: Connor Rigby Date: Fri, 14 Jun 2024 07:11:14 -0700 Subject: [PATCH] Fix dialyzer and credo Signed-off-by: Connor Rigby --- lib/vintage_net/connectivity/web_request.ex | 10 ++++------ lib/vintage_net/connectivity/when_where.ex | 10 ++++++---- test/vintage_net/connectivity/when_where_test.exs | 7 +------ 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/vintage_net/connectivity/web_request.ex b/lib/vintage_net/connectivity/web_request.ex index abba7bd9..957cefb1 100644 --- a/lib/vintage_net/connectivity/web_request.ex +++ b/lib/vintage_net/connectivity/web_request.ex @@ -63,9 +63,10 @@ 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! @@ -73,9 +74,6 @@ defmodule VintageNet.Connectivity.WebRequest do {:error, reason} -> {:error, reason} - - posix_error when is_atom(posix_error) -> - {:error, posix_error} end end diff --git a/lib/vintage_net/connectivity/when_where.ex b/lib/vintage_net/connectivity/when_where.ex index bf8173d4..df8a885c 100644 --- a/lib/vintage_net/connectivity/when_where.ex +++ b/lib/vintage_net/connectivity/when_where.ex @@ -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"}] @@ -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 diff --git a/test/vintage_net/connectivity/when_where_test.exs b/test/vintage_net/connectivity/when_where_test.exs index 174b541f..f53762e7 100644 --- a/test/vintage_net/connectivity/when_where_test.exs +++ b/test/vintage_net/connectivity/when_where_test.exs @@ -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.