View Source Resourceful.JSONAPI.Error (Resourceful v0.1.5)

Tools for converting errors formatted in accordance with Resourceful.Error into JSON:API-style errors.

JSON:API errors have a number of reserved top-level names:

  • code
  • detail
  • id
  • links
  • meta
  • source
  • status
  • title

Resourceful errors map to JSON:API errors as follows:

An error's type symbol is converted to a string for code. With the exception of meta and status the remainder of keys in an error's context are mapped to either the top-level attribute of the same name or, in the event the name is not a reserved name, it will be placed in meta which, if present, will always be a map.

status is a bit of a special case as "status" in a JSON:API error always refers to an HTTP status code, but it's quite possible many errors might have a status attribute in their context that has nothing to do with HTTP. As such, :http_status may be passed either as an option or as a key in a context map.

Link to this section Summary

Functions

Takes a list of errors, or an :error tuple with a list as the second element, and converts that list to JSON:API errors.

Returns a map of all non-reserved attributes from a context map.

Returns a JSON:API source map based on the :source attribute in a an error's context map.

Returns a JSON:API source map. Either

Returns the appropriate status attribute based on either the context map or an explicitly passed :http_status option. The value in a context takes precedence. The reason for this is that the keyword will often be used in conjunction with all/2 to apply a default but certain errors, when a situation allows for mixed errors with statuses, will want to be set explicitly apart from the default.

Converts a Resourceful error into a JSON:API error map which can then be converted to JSON. See module overview for details on conventions.

Link to this section Functions

Takes a list of errors, or an :error tuple with a list as the second element, and converts that list to JSON:API errors.

Returns a map of all non-reserved attributes from a context map.

Link to this function

parameter_source(source)

View Source
Link to this function

source(error, source_type \\ "pointer")

View Source

Returns a JSON:API source map based on the :source attribute in a an error's context map.

Link to this function

source_string(source, source_type)

View Source

Returns a JSON:API source map. Either:

  1. %{"pointer" => "/data/attributes/problem"}
  2. %{"parameter" => "fields[resource_type]"}
Link to this function

status(error, opts \\ [])

View Source

Returns the appropriate status attribute based on either the context map or an explicitly passed :http_status option. The value in a context takes precedence. The reason for this is that the keyword will often be used in conjunction with all/2 to apply a default but certain errors, when a situation allows for mixed errors with statuses, will want to be set explicitly apart from the default.

Link to this function

to_map(error, opts \\ [])

View Source

Converts a Resourceful error into a JSON:API error map which can then be converted to JSON. See module overview for details on conventions.