Oaskit.ErrorHandler.Default (oaskit v0.3.0)

View Source

The default error handler for validation errors.

Returns various HTTP error codes depending on the validation failure:

  • 422 Unprocessable Entity - When JSON schema errors when validating request bodies.
  • 415 Unsupported Media Type - When matching the request content-type to the accepted content-types.
  • 400 Bad Request - When validating query and path parameters.

Error formatting

For request specifically accepting HTML ("html" is found in the Accept header), this handler will present errors in an HTML document with basic styles.

In any other case, a JSON representation of errors is returned with the "application/json" content type.

Disable HTML entirely with the html_errors: false option when using the Oaskit.Plugs.ValidateRequest plug.

Summary

Functions

Returns a module-based JSON schema for json responses returned by this module when used as the handler of validation errors.

Functions

error_response_schema()

Returns a module-based JSON schema for json responses returned by this module when used as the handler of validation errors.

Example

operation :my_action,
  request_body: UserCreationParams,
  responses: [
    ok: User,
    default: Oaskit.ErrorHandler.Default.error_response_schema()
  ]

def my_action(conn, params) do
  # ...
end

handle_error(conn, reason, opts)

Callback implementation for Oaskit.ErrorHandler.handle_error/3.