1defmodule Plug.Conn.WrapperError do 2 @moduledoc """ 3 Wraps the connection in an error which is meant 4 to be handled upper in the stack. 5 6 Used by both `Plug.Debugger` and `Plug.ErrorHandler`. 7 """ 8 defexception [:conn, :kind, :reason, :stack] 9 10 def message(%{kind: kind, reason: reason, stack: stack}) do 11 Exception.format_banner(kind, reason, stack) 12 end 13 14 @doc """ 15 Reraises an error or a wrapped one. 16 """ 17 def reraise(_conn, :error, %__MODULE__{stack: stack} = reason) do 18 :erlang.raise(:error, reason, stack) 19 end 20 def reraise(conn, :error, reason) do 21 stack = System.stacktrace 22 wrapper = %__MODULE__{conn: conn, kind: :error, reason: reason, stack: stack} 23 :erlang.raise(:error, wrapper, stack) 24 end 25 def reraise(_conn, kind, reason) do 26 :erlang.raise(kind, reason, System.stacktrace) 27 end 28end 29