# `Urchin.Error`
[🔗](https://github.com/urth-inc/urchin/blob/v0.4.0/lib/urchin/error.ex#L1)

JSON-RPC / MCP error representation.

An `Urchin.Error` is both a struct and an exception, so handlers may either return
`{:error, Urchin.Error.t()}` or `raise` it. The dispatcher converts it into a
JSON-RPC error object on the wire.

# `t`

```elixir
@type t() :: %Urchin.Error{
  __exception__: true,
  code: integer(),
  data: term() | nil,
  message: String.t()
}
```

# `internal_error`

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

JSON-RPC internal error (-32603).

# `invalid_params`

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

JSON-RPC invalid params (-32602).

# `invalid_request`

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

JSON-RPC invalid request (-32600): the payload is not a valid request object.

# `method_not_found`

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

JSON-RPC method not found (-32601).

# `method_not_found_code`

```elixir
@spec method_not_found_code() :: integer()
```

Code constant for `method_not_found`.

# `new`

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

Builds an error with an explicit numeric code.

# `parse_error`

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

JSON-RPC parse error (-32700): invalid JSON was received.

# `to_map`

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

Serializes the error into the JSON-RPC `error` object shape. The `data` member
is omitted when nil.

# `url_elicitation_required_code`

```elixir
@spec url_elicitation_required_code() :: integer()
```

Code constant for the URL-elicitation-required error.

# `wrap`

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

Coerces an arbitrary value raised or returned by user code into an `Urchin.Error`.

`Urchin.Error` values pass through unchanged. Everything else becomes an internal
error so that exceptions never leak transport details to the client.

---

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