Oaskit.ErrorHandler behaviour (oaskit v0.3.0)

View Source

A behaviour for validation errors handlers.

Summary

Callbacks

Accepts the Plug.Conn struct, an error reason and the options passed to the Oaskit.Plugs.ValidateRequest plug.

Types

Callbacks

handle_error(t, reason, arg)

@callback handle_error(Plug.Conn.t(), reason(), arg :: term()) :: Plug.Conn.t()

Accepts the Plug.Conn struct, an error reason and the options passed to the Oaskit.Plugs.ValidateRequest plug.

This function is called when request validation fails and an error must be returned to the remote client. This means that function must send a response.

Responses can be sent just as in Phoenix controllers, using Plug.Conn.send_resp/3, Phoenix.Controller.json/2, Phoenix.Controller.text/2, etc.

The arg argument is the options given to Oaskit.Plugs.ValidateRequest. See this module documentation for more information.