Request.Validator.Plug (RequestValidator v1.0.2)

Copy Markdown View Source

Summary

Functions

Performs validations on conn.params If all validations are successful returns the connection struct Otherwise returns an error map in the following structure: %{param: ["some error", ...]} Will call the given on_error callback in case some validation failed

Init the Request.Validator.Plug with an optional error callback

The default callback to be invoked when there is a param that fails validation.

Functions

call(conn, arg)

Performs validations on conn.params If all validations are successful returns the connection struct Otherwise returns an error map in the following structure: %{param: ["some error", ...]} Will call the given on_error callback in case some validation failed

init(opts)

Init the Request.Validator.Plug with an optional error callback

and handlers with their corresponding request validator module.

plug Request.Validator.Plug,
  register: App.Requests.RegisterRequest,
  on_error: fn conn, errors -> json_resp(conn, "Handle your errors: #{inspect errors}") end

# A module that exports a `__validators__/0` method that returns
# a keyword list whose key is the action and value the validator/rules.
plug Request.Validator.Plug, ActionValidationCollector

on_error(conn, errors)

The default callback to be invoked when there is a param that fails validation.