# `GRPC.RPCError`
[🔗](https://github.com/elixir-grpc/grpc_core/blob/v1.0.1/lib/grpc/rpc_error.ex#L1)

The RPC error raised in server side and got in client side.

    # server side
    raise GRPC.RPCError, status: :unknown # preferred
    raise GRPC.RPCError, status: GRPC.Status.unknown, message: "error message"

    # client side
    {:error, error} = Your.Stub.unary_call(channel, request)

Error handling can be done with the `is_rpc_error/2` guard.

Expanding on the code above, the first option is for the guard to
be used in a `cond` or `case`, as follows:

    cond do
      is_rpc_error(error, GRPC.Status.not_found()) ->
        do_something_when_not_found()

      is_rpc_error(error, GRPC.Status.out_of_range()) ->
        do_something_when_out_of_range()

      true ->
        fallback_code()
    end

Another option is for the error handling to be written into a multi-clause function.
In such case we must define module attributes for each of the errors we want because
the functions in `GRPC.Status` can't be called directly inside the guard.

    ...
    handle_error(error)
    ...

    @not_found GRPC.Status.not_found()
    @out_of_range GRPC.Status.out_of_range()

    defp handle_error(error) when is_rpc_error(error, @not_found) do
      # not found
    end

    defp handle_error(error) when is_rpc_error(error, @out_of_range) do
      # out of range
    end

    defp handle_error(error) do
      # fallback
    end

See `GRPC.Status` for more details on possible statuses.

# `t`

```elixir
@type t() :: %GRPC.RPCError{
  __exception__: true,
  details: [Google.Protobuf.Any.t()] | nil,
  message: String.t(),
  status: GRPC.Status.t()
}
```

# `exception`

```elixir
@spec exception(status :: GRPC.Status.t() | atom(), message :: String.t()) :: t()
```

# `is_rpc_error`
*macro* 

# `new`

```elixir
@spec new(status :: atom()) :: t()
```

---

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