View Source AshJsonApi.ToJsonApiError protocol (ash_json_api v1.0.0-rc.6)

A protocol for turning an Ash exception into an AshJsonApi.Error

To use, implement the protocol for a builtin Ash exception type or for your own custom Ash exception.

Example

defmodule NotAvailable do
  use Ash.Error.Exception

  use Splode.Error,
    fields: [],
    class: :invalid

  defimpl AshJsonApi.ToJsonApiError do
    def to_json_api_error(error) do
      %AshJsonApi.Error{
        id: Ash.UUID.generate(),
        status_code: 409,
        code: "not_available",
        title: "not_available",
        detail: "Not available"
      }
    end
  end
end

Summary

Types

t()

All the types that implement this protocol.

Types

@type t() :: term()

All the types that implement this protocol.

Functions

Link to this function

to_json_api_error(struct)

View Source
@spec to_json_api_error(term()) :: AshJsonApi.Error.t() | [AshJsonApi.Error.t()]