Skip to content

Commit bd32d51

Browse files
committed
Handle endpoint exceptions
1 parent 64bd2c0 commit bd32d51

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

dev.exs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ defmodule ErrorTrackerDev.Live do
156156
<li>
157157
<.link href="/exception">Generate an exception from the controller</.link>
158158
</li>
159+
<li>
160+
<.link href="/plug_exception">Generate an exception from the router</.link>
161+
</li>
159162
<li>
160163
<.link href="/exit">Generate an exit from the controller</.link>
161164
</li>
@@ -205,6 +208,8 @@ defmodule ErrorTrackerDev.Endpoint do
205208

206209
# Use a custom Content Security Policy
207210
plug :set_csp
211+
# Raise an exception in the /plug_exception path
212+
plug :plug_exception
208213
# Our custom router which allows us to have regular controllers and live views
209214
plug ErrorTrackerDev.Router
210215

@@ -220,6 +225,12 @@ defmodule ErrorTrackerDev.Endpoint do
220225
|> Plug.Conn.assign(:custom_csp_nonce, "#{nonce}")
221226
|> Plug.Conn.put_resp_header("content-security-policy", Enum.join(policies, " "))
222227
end
228+
229+
defp plug_exception(conn = %Plug.Conn{path_info: path_info}, _opts) when is_list(path_info) do
230+
if "plug_exception" in path_info,
231+
do: raise("Crashed in Endpoint"),
232+
else: conn
233+
end
223234
end
224235

225236
defmodule ErrorTrackerDev.ErrorView do

0 commit comments

Comments
 (0)