W3cubDocs

/Phoenix

Plug.Exception protocol

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

Types

t()

Functions

actions(exception)

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

status(exception)

Receives an exception and returns its HTTP status code.

Types

action()

Specs

action() :: %{label: String.t(), handler: {module(), atom(), list()}}

t()

Specs

t() :: term()

Functions

actions(exception)

Specs

actions(t()) :: [action()]

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 action
  • handler 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

status(exception)

Specs

status(t()) :: Plug.Conn.status()

Receives an exception and returns its HTTP status code.

© 2013 Plataformatec
Licensed under the Apache License, Version 2.0.
https://hexdocs.pm/plug/Plug.Exception.html