View Source Guardian.Plug.ErrorHandler behaviour (Guardian v2.3.2)

Optional Behaviour for creating error handlers for Guardian.Plug.Pipeline.


Error handler

When using plugs, you'll need to specify an error handler module.

The error_handler module requires an auth_error function that receives the conn, the reason tuple and the options.

defmodule MyApp.AuthErrorHandler do
  @behaviour Guardian.Plug.ErrorHandler

  @impl Guardian.Plug.ErrorHandler
  def auth_error(conn, {type, reason}, opts) do

By default, Guardian will emit types of:

  • :unauthorized
  • :invalid_token
  • :already_authenticated
  • :no_resource_found

Link to this section Summary

Link to this section Callbacks

Link to this callback

auth_error(conn, {}, opts)

View Source
@callback auth_error(
  conn :: Plug.Conn.t(),
  {type :: atom(), reason :: atom()},
  opts :: Guardian.options()
) :: Plug.Conn.t()