From 1fb39957a63af415d403d996d06f544bc0d1eb52 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Mon, 21 Mar 2022 14:24:45 +0200 Subject: [PATCH] Import Oban error handling --- lib/plausible/google/api.ex | 4 ---- .../templates/site/settings_general.html.eex | 8 +++++++- lib/telemetry.ex | 10 ++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/plausible/google/api.ex b/lib/plausible/google/api.ex index d57d22659..a1da6565f 100644 --- a/lib/plausible/google/api.ex +++ b/lib/plausible/google/api.ex @@ -296,8 +296,6 @@ defmodule Plausible.Google.Api do pageToken: page_token } - Logger.debug(report) - res = HTTPoison.post!( "https://analyticsreporting.googleapis.com/v4/reports:batchGet", @@ -305,8 +303,6 @@ defmodule Plausible.Google.Api do Authorization: "Bearer #{request.auth.access_token}" ) - Logger.debug(res.body) - if res.status_code == 200 do report = List.first(Jason.decode!(res.body)["reports"]) data = report["data"]["rows"] diff --git a/lib/plausible_web/templates/site/settings_general.html.eex b/lib/plausible_web/templates/site/settings_general.html.eex index 6daad6dd2..51b24d3c3 100644 --- a/lib/plausible_web/templates/site/settings_general.html.eex +++ b/lib/plausible_web/templates/site/settings_general.html.eex @@ -83,9 +83,15 @@
Linked Google account: <%= @site.google_auth.email %> + <%= if @imported_data && @imported_data.status == "error" do %> +
+ Your last GA import resulted in an error. You can try again below. +
+ <% end %> + <%= case @google_profiles do %> <% {:ok, profiles} -> %> -

+

Select the Google Analytics view id you would like to import data from.

diff --git a/lib/telemetry.ex b/lib/telemetry.ex index b9dd8c7c0..ac1fd1d4e 100644 --- a/lib/telemetry.ex +++ b/lib/telemetry.ex @@ -5,10 +5,20 @@ defmodule ErrorReporter do |> Map.take([:id, :args, :meta, :queue, :worker]) |> Map.merge(measure) + maybe_log_import_error(job) + Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: extra) end def handle_event([:oban, :circuit, :trip], _measure, meta, _) do Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: meta) end + + defp maybe_log_import_error(job) do + site = Plausible.Repo.get(Plausible.Site, job.args["site_id"]) + + if site do + Plausible.Site.import_failure(site) |> Plausible.Repo.update!() + end + end end