View Source CoseDellaVitaEx.Types.ErrorTypes (CoseDellaVitaEx v0.2.0)

Error types. When implemented, makes it possible for clients to query what exactly went wrong

Link to this section Summary

Functions

Translate changeset errors into CoseDellaVitaEx.Errors.* structs that are translated into specific, typed GraphQL data-errors.

Resolve the type of an "object to identify" (a map or a struct) (that is expected to be an error). The object to identify must either

Same as resolve_error_type/2 but the resolved type must be in the allowlist or be downgraded to :generic_error. A warning about the downgrade is logged.

Link to this section Functions

Link to this function

graphql_changeset_error_traverser(arg, error_mapper)

View Source
@spec graphql_changeset_error_traverser(
  {binary(), keyword() | map()},
  (String.t(), map() -> struct())
) :: struct()

Translate changeset errors into CoseDellaVitaEx.Errors.* structs that are translated into specific, typed GraphQL data-errors.

examples-doctests

Examples / doctests

See CoseDellaVitaEx.Helpers.add_changeset_errors/5.

Link to this function

resolve_error_type(object_to_identify, execution)

View Source
@spec resolve_error_type(
  any(),
  struct()
) :: atom() | nil

Resolve the type of an "object to identify" (a map or a struct) (that is expected to be an error). The object to identify must either:

  • define an :error_type atom that matches a specific Absinthe object type
  • have a :path and :message to be identified as a :generic_error type

## Examples / doctests

iex> resolve_error_type(%{error_type: :bicycle_error}, nil)
:bicycle_error
iex> resolve_error_type(%{path: ["name"], message: "this is a stupid name"}, nil)
:generic_error
iex> resolve_error_type("anything else", nil)
nil
Link to this function

resolve_error_type(object_to_identify, execution, allowlist)

View Source
@spec resolve_error_type(any(), struct(), nil | Enum.t()) :: atom() | nil

Same as resolve_error_type/2 but the resolved type must be in the allowlist or be downgraded to :generic_error. A warning about the downgrade is logged.

examples-doctests

Examples / doctests

iex> resolve_error_type(%{error_type: :bicycle_error}, nil, [:some_other_error])
:generic_error
iex> resolve_error_type(%{error_type: :bicycle_error}, nil, [:bicycle_error])
:bicycle_error