Small fixes
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
6668a663a7
commit
cb4a801519
|
@ -621,6 +621,10 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
Logger.info("Actor was deleted")
|
Logger.info("Actor was deleted")
|
||||||
{:error, :actor_deleted}
|
{:error, :actor_deleted}
|
||||||
|
|
||||||
|
{:error, e} ->
|
||||||
|
Logger.warn("Failed to make actor from url")
|
||||||
|
{:error, e}
|
||||||
|
|
||||||
e ->
|
e ->
|
||||||
Logger.warn("Failed to make actor from url")
|
Logger.warn("Failed to make actor from url")
|
||||||
{:error, e}
|
{:error, e}
|
||||||
|
@ -801,6 +805,10 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||||
Logger.info("Response HTTP 410")
|
Logger.info("Response HTTP 410")
|
||||||
{:error, :actor_deleted}
|
{:error, :actor_deleted}
|
||||||
|
|
||||||
|
{:error, e} ->
|
||||||
|
Logger.warn("Could not decode actor at fetch #{url}, #{inspect(e)}")
|
||||||
|
{:error, e}
|
||||||
|
|
||||||
e ->
|
e ->
|
||||||
Logger.warn("Could not decode actor at fetch #{url}, #{inspect(e)}")
|
Logger.warn("Could not decode actor at fetch #{url}, #{inspect(e)}")
|
||||||
{:error, e}
|
{:error, e}
|
||||||
|
|
|
@ -132,7 +132,8 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Discussions do
|
||||||
)
|
)
|
||||||
|
|
||||||
args
|
args
|
||||||
|> Map.update(:title, "", &String.trim/1)
|
# title might be nil
|
||||||
|
|> Map.update(:title, "", fn title -> String.trim(title || "") end)
|
||||||
|> Map.put(:text, text)
|
|> Map.put(:text, text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -115,7 +115,7 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
||||||
def create_user(_parent, args, _resolution) do
|
def create_user(_parent, args, _resolution) do
|
||||||
with :registration_ok <- check_registration_config(args),
|
with :registration_ok <- check_registration_config(args),
|
||||||
{:ok, %User{} = user} <- Users.register(args),
|
{:ok, %User{} = user} <- Users.register(args),
|
||||||
{:ok, %Bamboo.Email{}} <-
|
%Bamboo.Email{} <-
|
||||||
Email.User.send_confirmation_email(user, Map.get(args, :locale, "en")) do
|
Email.User.send_confirmation_email(user, Map.get(args, :locale, "en")) do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
else
|
else
|
||||||
|
@ -206,7 +206,7 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
|
||||||
Users.get_user_by_email(email, activated: true, unconfirmed: false),
|
Users.get_user_by_email(email, activated: true, unconfirmed: false),
|
||||||
{:can_reset_password, true} <-
|
{:can_reset_password, true} <-
|
||||||
{:can_reset_password, Authenticator.can_reset_password?(user)},
|
{:can_reset_password, Authenticator.can_reset_password?(user)},
|
||||||
{:ok, %Bamboo.Email{} = _email_html} <-
|
{:ok, %Bamboo.Email{}} <-
|
||||||
Email.User.send_password_reset_email(user, Map.get(args, :locale, locale)) do
|
Email.User.send_password_reset_email(user, Map.get(args, :locale, locale)) do
|
||||||
{:ok, email}
|
{:ok, email}
|
||||||
else
|
else
|
||||||
|
|
|
@ -16,7 +16,7 @@ defmodule Mobilizon do
|
||||||
|
|
||||||
alias Mobilizon.{Config, Storage, Web}
|
alias Mobilizon.{Config, Storage, Web}
|
||||||
alias Mobilizon.Federation.ActivityPub
|
alias Mobilizon.Federation.ActivityPub
|
||||||
alias Mobilizon.Service.ErrorPage
|
alias Mobilizon.Service.{ErrorPage, ErrorReporter}
|
||||||
alias Mobilizon.Service.Export.{Feed, ICalendar}
|
alias Mobilizon.Service.Export.{Feed, ICalendar}
|
||||||
|
|
||||||
@name Mix.Project.config()[:name]
|
@name Mix.Project.config()[:name]
|
||||||
|
@ -68,6 +68,14 @@ defmodule Mobilizon do
|
||||||
|
|
||||||
Logger.add_backend(Sentry.LoggerBackend)
|
Logger.add_backend(Sentry.LoggerBackend)
|
||||||
:ok = Oban.Telemetry.attach_default_logger()
|
:ok = Oban.Telemetry.attach_default_logger()
|
||||||
|
|
||||||
|
:telemetry.attach_many(
|
||||||
|
"oban-errors",
|
||||||
|
[[:oban, :job, :exception], [:oban, :circuit, :trip]],
|
||||||
|
&ErrorReporter.handle_event/4,
|
||||||
|
%{}
|
||||||
|
)
|
||||||
|
|
||||||
Supervisor.start_link(children, strategy: :one_for_one, name: Mobilizon.Supervisor)
|
Supervisor.start_link(children, strategy: :one_for_one, name: Mobilizon.Supervisor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
17
lib/service/error_reporter.ex
Normal file
17
lib/service/error_reporter.ex
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
defmodule Mobilizon.Service.ErrorReporter do
|
||||||
|
@moduledoc """
|
||||||
|
Module to delegate all exceptions to Sentry
|
||||||
|
"""
|
||||||
|
def handle_event([:oban, :job, :exception], measure, %{job: job} = meta, _) do
|
||||||
|
extra =
|
||||||
|
job
|
||||||
|
|> Map.take([:id, :args, :meta, :queue, :worker])
|
||||||
|
|> Map.merge(measure)
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
|
@ -5,30 +5,26 @@ defmodule Mobilizon.Web.Email.Mailer do
|
||||||
use Bamboo.Mailer, otp_app: :mobilizon
|
use Bamboo.Mailer, otp_app: :mobilizon
|
||||||
|
|
||||||
def send_email_later(email) do
|
def send_email_later(email) do
|
||||||
try do
|
Mobilizon.Web.Email.Mailer.deliver_later!(email)
|
||||||
Mobilizon.Web.Email.Mailer.deliver_later!(email)
|
rescue
|
||||||
rescue
|
error ->
|
||||||
error ->
|
Sentry.capture_exception(error,
|
||||||
Sentry.capture_exception(error,
|
stacktrace: __STACKTRACE__,
|
||||||
stacktrace: __STACKTRACE__,
|
extra: %{extra: "Error while sending email"}
|
||||||
extra: %{extra: "Error while sending email"}
|
)
|
||||||
)
|
|
||||||
|
|
||||||
reraise error, __STACKTRACE__
|
reraise error, __STACKTRACE__
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_email(email) do
|
def send_email(email) do
|
||||||
try do
|
Mobilizon.Web.Email.Mailer.deliver_now!(email)
|
||||||
Mobilizon.Web.Email.Mailer.deliver_now!(email)
|
rescue
|
||||||
rescue
|
error ->
|
||||||
error ->
|
Sentry.capture_exception(error,
|
||||||
Sentry.capture_exception(error,
|
stacktrace: __STACKTRACE__,
|
||||||
stacktrace: __STACKTRACE__,
|
extra: %{extra: "Error while sending email"}
|
||||||
extra: %{extra: "Error while sending email"}
|
)
|
||||||
)
|
|
||||||
|
|
||||||
reraise error, __STACKTRACE__
|
reraise error, __STACKTRACE__
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -80,7 +80,7 @@ defmodule Mobilizon.Web.Email.User do
|
||||||
Users.update_user(user, %{
|
Users.update_user(user, %{
|
||||||
"confirmation_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second)
|
"confirmation_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second)
|
||||||
}),
|
}),
|
||||||
{:ok, %Bamboo.Email{}} <- send_confirmation_email(user, locale) do
|
%Bamboo.Email{} <- send_confirmation_email(user, locale) do
|
||||||
Logger.info("Sent confirmation email again to #{user.email}")
|
Logger.info("Sent confirmation email again to #{user.email}")
|
||||||
{:ok, user.email}
|
{:ok, user.email}
|
||||||
end
|
end
|
||||||
|
@ -132,7 +132,7 @@ defmodule Mobilizon.Web.Email.User do
|
||||||
"reset_password_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second)
|
"reset_password_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second)
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
{:ok, %Bamboo.Email{} = mail} <-
|
%Bamboo.Email{} = mail <-
|
||||||
user_updated
|
user_updated
|
||||||
|> Email.User.reset_password_email(locale)
|
|> Email.User.reset_password_email(locale)
|
||||||
|> Email.Mailer.send_email_later() do
|
|> Email.Mailer.send_email_later() do
|
||||||
|
|
Loading…
Reference in a new issue