Resourceful.JSONAPI.Error (Resourceful v0.1.6)
View SourceTools 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:
codedetailidlinksmetasourcestatustitle
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.
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.
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:
%{"pointer" => "/data/attributes/problem"}%{"parameter" => "fields[resource_type]"}
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.