# `AshJsonApi.ToJsonApiError`
[🔗](https://github.com/ash-project/ash_json_api/blob/v1.6.5/lib/ash_json_api/error/to_json_api_error.ex#L5)

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

```elixir
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
```

# `t`

```elixir
@type t() :: term()
```

All the types that implement this protocol.

# `to_json_api_error`

```elixir
@spec to_json_api_error(term()) :: AshJsonApi.Error.t() | [AshJsonApi.Error.t()]
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
