View Source Returning Errors
This guide could use some improvement.
You can help! Please fork the absinthe repository, edit
guides/errors.md
, and submit a pull request.
One or more errors for a field can be returned in a single {:error, error_value}
tuple.
error_value
can be:
- A simple error message string.
- A map containing
:message
key, plus any additional serializable metadata. - A keyword list containing a
:message
key, plus any additional serializable metadata. - A list containing multiple of any/all of these.
- Any other value compatible with
to_string/1
.
basic-errors
Basic Errors
A simple error message:
{:error, "Something bad happened"}
Multiple error messages:
{:error, ["Something bad", "Even worse"]}
Single custom errors (note the required :message
keys):
{:error, message: "Unknown user", code: 21}
{:error, %{message: "A database error occurred", details: format_db_error(some_value)}}
Three errors of mixed types:
{:error, ["Simple message", [message: "A keyword list error", code: 1], %{message: "A map error"}]}
Generic handler for interoperability with errors from other libraries:
{:error, :foo}
{:error, 1.0}
{:error, 2}
ecto-changeset-errors
Ecto.Changeset Errors
You may want to look at the Absinthe ErrorPayload package.