# `Snodo.Error`
[🔗](https://github.com/joshrotenberg/snodo/blob/v0.2.0/lib/snodo/error.ex#L1)

A protocol-neutral error with JSON-RPC-compatible defaults.

# `kind`

```elixir
@type kind() ::
  :json_rpc | :protocol | :transport | :execution | :authorization | :extension
```

# `t`

```elixir
@type t() :: %Snodo.Error{
  cause: term() | nil,
  code: integer(),
  data: term() | nil,
  kind: kind(),
  message: String.t()
}
```

# `authorization`

```elixir
@spec authorization(integer(), String.t(), term() | nil) :: t()
```

Builds an application authorization refusal.

`code` is the application's own choice; JSON-RPC reserves -32000..-32099 for
implementation-defined server errors. `snodo` never invents one.

# `execution`

```elixir
@spec execution(term()) :: t()
```

Wraps a failure reason as an execution error.

An `Snodo.Error` is returned unchanged. Any other `reason` becomes code
-32603 with the message `"Tool execution failed"`, kind `:execution`, and
`reason` in the `cause` field, which `to_json_rpc/1` leaves out.

# `internal`

```elixir
@spec internal(String.t(), term() | nil) :: t()
```

Builds an internal error: code -32603, kind `:execution`.

`cause` is kept in the struct's `cause` field. `to_json_rpc/1` leaves it
out, so it is not sent to the client.

# `invalid_params`

```elixir
@spec invalid_params(String.t(), term() | nil) :: t()
```

Builds an invalid params error: code -32602, kind `:protocol`.

`data`, when not `nil`, is sent as the error's `"data"` and must be a JSON
value. Return this from a handler when the request should fail as a
JSON-RPC error, for example a resource that does not exist.

# `invalid_request`

```elixir
@spec invalid_request(String.t()) :: t()
```

Builds a JSON-RPC invalid request error: code -32600, kind `:json_rpc`.

# `method_not_found`

```elixir
@spec method_not_found(String.t()) :: t()
```

Builds a method-not-found error for `method`: code -32601, kind `:protocol`,
message `"Method not found: <method>"`.

# `parse_error`

```elixir
@spec parse_error(String.t()) :: t()
```

Builds a JSON-RPC parse error: code -32700, kind `:json_rpc`.

# `to_json_rpc`

```elixir
@spec to_json_rpc(t()) :: map()
```

Returns the JSON-RPC error object: `"code"`, `"message"`, and `"data"` when
`data` is not `nil`. `kind` and `cause` are not included.

---

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