File size: 825 Bytes
8da2481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
defmodule PlausibleWeb.ErrorReportController do
  use PlausibleWeb, :controller

  plug PlausibleWeb.RequireAccountPlug

  def submit_error_report(conn, %{
        "error" => %{"trace_id" => trace_id, "user_feedback" => feedback}
      }) do
    if String.length(String.trim(feedback)) > 5 do
      reported_by = "#{conn.assigns.current_user.name} <#{conn.assigns.current_user.email}>"
      email_template = PlausibleWeb.Email.error_report(reported_by, trace_id, feedback)

      Plausible.Mailer.deliver_later(email_template)
    end

    thanks(conn)
  end

  def submit_error_report(conn, _params) do
    thanks(conn)
  end

  defp thanks(conn) do
    conn
    |> put_view(PlausibleWeb.ErrorView)
    |> render("server_error_report_thanks.html",
      layout: {PlausibleWeb.LayoutView, "base_error.html"}
    )
  end
end