View Source IdempotencyPlug.Handler behaviour (IdempotencyPlug v0.1.2)

Module that defines the plug handler callbacks.

examples

Examples

defmodule MyAppWeb.IdempotencyPlugHandler do
  @behaviour IdempotencyPlug.Handler

  import Phoenix.Controller
  import Plug.Conn

  @impl true
  def idempotent_id(conn, id) do
    IdempotencyPlug.Handler.idempotent_id(conn, id)
  end

  @impl true
  def resp_error(conn, error) do
    conn
    |> put_status(IdempotencyPlug.Handler.status(error))
    |> json(%{error: IdempotencyPlug.Handler.message(error)})
  end
end

Link to this section Summary

Functions

Returns the request ID as-is.

Returns message for the error atom.

Updates the conn with a JSON encoded response body and status code.

Returns the status for the error atom.

Link to this section Types

@type error() ::
  :multiple_headers
  | :no_headers
  | :concurrent_request
  | :fingerprint_mismatch
  | :halted
@type request_id() :: binary()

Link to this section Callbacks

Link to this callback

idempotent_id(t, request_id)

View Source
@callback idempotent_id(Plug.Conn.t(), request_id()) :: binary()
@callback resp_error(Plug.Conn.t(), error()) :: Plug.Conn.t()

Link to this section Functions

Returns the request ID as-is.

@spec message(error()) :: binary()

Returns message for the error atom.

Updates the conn with a JSON encoded response body and status code.

@spec status(error()) :: integer()

Returns the status for the error atom.