View Source Plug.Exception protocol (Plug v1.16.1)
A protocol that extends exceptions to be status-code aware.
By default, it looks for an implementation of the protocol,
otherwise checks if the exception has the :plug_status
field
or simply returns 500.
Summary
Functions
Receives an exception and returns the possible actions that could be triggered for that error. Should return a list of actions in the following structure
Receives an exception and returns its HTTP status code.
Types
@type t() :: term()
All the types that implement this protocol.
Functions
Receives an exception and returns the possible actions that could be triggered for that error. Should return a list of actions in the following structure:
%{
label: "Text that will be displayed in the button",
handler: {Module, :function, [args]}
}
Where:
label
a string/binary that names this actionhandler
a MFArgs that will be executed when this action is triggered
It will be rendered in the Plug.Debugger
generated error page as buttons showing the label
that upon pressing executes the MFArgs defined in the handler
.
Examples
defimpl Plug.Exception, for: ActionableExample do
def actions(_), do: [%{label: "Print HI", handler: {IO, :puts, ["Hi!"]}}]
end
@spec status(t()) :: Plug.Conn.status()
Receives an exception and returns its HTTP status code.