Skip to content

Commit

Permalink
[Enhancement] Show error messages in-app for easier triage (#365)
Browse files Browse the repository at this point in the history
* Added an improved error message screen with actionable details

* Added a basic 404 page

* fixed tests
  • Loading branch information
kieraneglin authored Aug 23, 2024
1 parent a6c61cc commit 14b8ecb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ config :pinchflat, PinchflatWeb.Endpoint,
adapter: Phoenix.Endpoint.Cowboy2Adapter,
render_errors: [
formats: [html: PinchflatWeb.ErrorHTML, json: PinchflatWeb.ErrorJSON],
layout: false
root_layout: {PinchflatWeb.Layouts, :root},
layout: {PinchflatWeb.Layouts, :app}
],
pubsub_server: Pinchflat.PubSub,
live_view: [signing_salt: "/t5878kO"]
Expand Down
9 changes: 1 addition & 8 deletions lib/pinchflat_web/controllers/error_html.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
defmodule PinchflatWeb.ErrorHTML do
use PinchflatWeb, :html

# If you want to customize your error pages,
# uncomment the embed_templates/1 call below
# and add pages to the error directory:
#
# * lib/pinchflat_web/controllers/error_html/404.html.heex
# * lib/pinchflat_web/controllers/error_html/500.html.heex
#
# embed_templates "error_html/*"
embed_templates "error_html/*"

# The default is to render a plain text page based on
# the template name. For example, "404.html" becomes
Expand Down
3 changes: 3 additions & 0 deletions lib/pinchflat_web/controllers/error_html/404.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<section>
<h2 class="text-title-md2 font-bold text-white">404 (not found)</h2>
</section>
29 changes: 29 additions & 0 deletions lib/pinchflat_web/controllers/error_html/500.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<section>
<h2 class="text-title-md2 font-bold text-white">Internal Server Error</h2>
<p class="text-body-md text-white mt-2">
This shouldn't happen! Please make a
<.inline_link href="https://github.com/kieraneglin/pinchflat/issues/new/choose">GitHub issue</.inline_link>
with the following information:
</p>

<ul class="list-disc ml-8 mb-8">
<li>What you were doing when you saw this page</li>
<li>
Your system details and logs from
<.inline_link href={~p"/app_info"}>app info</.inline_link>
</li>
<li>All the information in the textarea below (use select all + copy)</li>
</ul>
<textarea class="w-full min-h-96 font-mono inline-block rounded-lg" readonly>
**Status**:
`<%= if Map.has_key?(assigns, :status), do: @status, else: "" %>`

**Reason**:
`<%= if Map.has_key?(assigns, :reason), do: inspect(@reason), else: "" %>`

**Stacktrace**:
```
<%= if Map.has_key?(assigns, :stack), do: Exception.format_stacktrace(@stack), else: "" %>
```
</textarea>
</section>
4 changes: 2 additions & 2 deletions test/pinchflat_web/controllers/error_html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ defmodule PinchflatWeb.ErrorHTMLTest do
import Phoenix.Template

test "renders 404.html" do
assert render_to_string(PinchflatWeb.ErrorHTML, "404", "html", []) == "Not Found"
assert render_to_string(PinchflatWeb.ErrorHTML, "404", "html", []) =~ "404 (not found)"
end

test "renders 500.html" do
assert render_to_string(PinchflatWeb.ErrorHTML, "500", "html", []) == "Internal Server Error"
assert render_to_string(PinchflatWeb.ErrorHTML, "500", "html", []) =~ "Internal Server Error"
end
end

0 comments on commit 14b8ecb

Please sign in to comment.