Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Fixup error reporting (ref #2181) (#2204)
Adam Rutkowskicc4d4bb8e0e8
diff --git a/lib/plausible/google/http.ex b/lib/plausible/google/http.exindex 41603dde95..5bfbfe7753 100644--- a/lib/plausible/google/http.ex+++ b/lib/plausible/google/http.ex@@ -105,7 +105,7 @@ defmodule Plausible.Google.HTTP do|> then(&{:ok, &1}){:error, reason} = e ->- Logger.error("Google Analytics: failed to list sites: #{reason}")+ Logger.error("Google Analytics: failed to list sites: #{inspect(reason)}")eendend@@ -142,8 +142,8 @@ defmodule Plausible.Google.HTTP doSentry.capture_message("Error fetching Google view ID", extra: Jason.decode!(body)){:error, body}- {:error, %{reason: reason}} ->- Sentry.capture_message("Error fetching Google view ID", extra: inspect(reason))+ {:error, %{reason: reason} = e} ->+ Sentry.capture_message("Error fetching Google view ID", extra: e){:error, reason}endend@@ -187,8 +187,8 @@ defmodule Plausible.Google.HTTP doSentry.capture_message("Error fetching Google queries", extra: Jason.decode!(body)){:error, :unknown}- {:error, %{reason: reason}} ->- Sentry.capture_message("Error fetching Google queries", extra: reason)+ {:error, %{reason: _} = e} ->+ Sentry.capture_message("Error fetching Google queries", extra: e){:error, :unknown}endend@@ -218,8 +218,8 @@ defmodule Plausible.Google.HTTP do|> Map.get("error")|> then(&{:error, &1})- {:error, %{reason: reason}} ->- Sentry.capture_message("Error fetching Google queries", extra: reason)+ {:error, %{reason: _} = e} ->+ Sentry.capture_message("Error fetching Google queries", extra: e){:error, :unknown}endend@@ -265,8 +265,8 @@ defmodule Plausible.Google.HTTP doSentry.capture_message("Error fetching Google view ID", extra: Jason.decode!(body)){:error, body}- {:error, %{reason: reason}} ->- Sentry.capture_message("Error fetching Google view ID", extra: reason)+ {:error, %{reason: reason} = e} ->+ Sentry.capture_message("Error fetching Google view ID", extra: e){:error, reason}endenddiff --git a/test/plausible/http_client_test.exs b/test/plausible/http_client_test.exsindex 7c2f4a3c51..08b4d3e4ed 100644--- a/test/plausible/http_client_test.exs+++ b/test/plausible/http_client_test.exs@@ -1,5 +1,5 @@defmodule Plausible.HTTPClientTest do- use ExUnit.Case, async: true+ use ExUnit.Case, async: falsealias Plausible.HTTPClientalias Plug.Conn@@ -10,19 +10,21 @@ defmodule Plausible.HTTPClientTest doendtest "get/2 works", %{bypass: bypass} do- Bypass.expect_once(bypass, "GET", "/", fn conn ->+ Bypass.expect_once(bypass, "GET", "/get", fn conn ->Conn.resp(conn, 200, "ok")end)- assert {:ok, %Finch.Response{status: 200, body: "ok"}} = HTTPClient.get(bypass_url(bypass))+ assert {:ok, %Finch.Response{status: 200, body: "ok"}} =+ HTTPClient.get(bypass_url(bypass, path: "/get"))endtest "post/3 works", %{bypass: bypass} do- Bypass.expect_once(bypass, "POST", "/", fn conn ->+ Bypass.expect_once(bypass, "POST", "/post", fn conn ->Conn.resp(conn, 200, "ok")end)- assert {:ok, %Finch.Response{status: 200, body: "ok"}} = HTTPClient.post(bypass_url(bypass))+ assert {:ok, %Finch.Response{status: 200, body: "ok"}} =+ HTTPClient.post(bypass_url(bypass, path: "/post"))endtest "post/3 doesn't alter params if binary passed",@@ -32,7 +34,7 @@ defmodule Plausible.HTTPClientTest dobody = "raw binary"headers = []- Bypass.expect_once(bypass, "POST", "/", fn conn ->+ Bypass.expect_once(bypass, "POST", "/post", fn conn ->opts = Plug.Parsers.init(parsers: [:urlencoded, {:json, json_decoder: Jason}])conn@@ -41,7 +43,7 @@ defmodule Plausible.HTTPClientTest doend)assert {:ok, %Finch.Response{status: 200, body: ^body}} =- HTTPClient.post(bypass_url(bypass), headers, body)+ HTTPClient.post(bypass_url(bypass, path: "/post"), headers, body)endtest "post/3 URL-encodes params if request content-type is set to application/x-www-form-urlencoded and a map is supplied",@@ -51,7 +53,7 @@ defmodule Plausible.HTTPClientTest dobody = %{hello: :world, alice: :bob}headers = [{"Content-Type", "application/x-www-form-urlencoded"}]- Bypass.expect_once(bypass, "POST", "/", fn conn ->+ Bypass.expect_once(bypass, "POST", "/post", fn conn ->opts = Plug.Parsers.init(parsers: [:urlencoded])conn = Plug.Parsers.call(conn, opts)@@ -62,7 +64,7 @@ defmodule Plausible.HTTPClientTest doend)assert {:ok, %Finch.Response{status: 200, body: "ok"}} =- HTTPClient.post(bypass_url(bypass), headers, body)+ HTTPClient.post(bypass_url(bypass, path: "/post"), headers, body)endtest "post/3 JSON-encodes params if request content-type is other than application/x-www-form-urlencoded and a map is supplied",@@ -100,7 +102,7 @@ defmodule Plausible.HTTPClientTest doHTTPClient.post(bypass_url(bypass, path: "/any"), headers_no_content_type, params)end- defp bypass_url(bypass, opts \\ []) do+ defp bypass_url(bypass, opts) doport = bypass.portpath = Keyword.get(opts, :path, "/")