2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.ErrorView do
|
|
|
|
use PlausibleWeb, :view
|
|
|
|
|
2020-05-25 12:25:41 +03:00
|
|
|
def render("500.json", _assigns) do
|
2019-11-19 07:30:42 +03:00
|
|
|
%{
|
|
|
|
status: 500,
|
2020-05-25 12:25:41 +03:00
|
|
|
message: "Server error"
|
2019-11-19 07:30:42 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
def render("404.html", assigns) do
|
2020-06-08 10:35:13 +03:00
|
|
|
render(
|
|
|
|
"error.html",
|
|
|
|
Map.merge(
|
|
|
|
%{
|
|
|
|
layout: false,
|
|
|
|
status: 404,
|
|
|
|
message: "Oops! There's nothing here"
|
|
|
|
},
|
|
|
|
assigns
|
|
|
|
)
|
|
|
|
)
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def render("500.html", assigns) do
|
2021-04-23 12:04:26 +03:00
|
|
|
case Sentry.get_last_event_id_and_source() do
|
|
|
|
{event_id, :plug} when is_binary(event_id) ->
|
|
|
|
current_user = assigns[:current_user]
|
|
|
|
|
|
|
|
opts =
|
|
|
|
%{
|
|
|
|
eventId: event_id,
|
2021-04-23 14:40:57 +03:00
|
|
|
user: %{
|
|
|
|
name: current_user && current_user.name,
|
|
|
|
email: current_user && current_user.email
|
|
|
|
}
|
2021-04-23 12:04:26 +03:00
|
|
|
}
|
|
|
|
|> Jason.encode!()
|
|
|
|
|
|
|
|
~E"""
|
|
|
|
<script src="https://browser.sentry-cdn.com/5.9.1/bundle.min.js" integrity="sha384-/x1aHz0nKRd6zVUazsV6CbQvjJvr6zQL2CHbQZf3yoLkezyEtZUpqUNnOLW9Nt3v" crossorigin="anonymous"></script>
|
|
|
|
<script>
|
|
|
|
Sentry.init({ dsn: '<%= Sentry.Config.dsn() %>' });
|
|
|
|
Sentry.showReportDialog(<%= raw opts %>)
|
|
|
|
</script>
|
|
|
|
"""
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
render(
|
|
|
|
"error.html",
|
|
|
|
Map.merge(
|
|
|
|
%{
|
|
|
|
layout: false,
|
|
|
|
status: 500,
|
|
|
|
message: "Oops! Looks like we're having server issues"
|
|
|
|
},
|
|
|
|
assigns
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def template_not_found(template, assigns) do
|
|
|
|
status = String.trim_trailing(template, ".html")
|
|
|
|
|
2020-06-08 10:35:13 +03:00
|
|
|
render(
|
|
|
|
"error.html",
|
|
|
|
Map.merge(
|
|
|
|
%{
|
|
|
|
layout: false,
|
|
|
|
status: status,
|
|
|
|
message: Phoenix.Controller.status_message_from_template(template)
|
|
|
|
},
|
|
|
|
assigns
|
|
|
|
)
|
|
|
|
)
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
end
|