# `Sinetex.Error`
[🔗](https://github.com/openspb/sinetex/blob/v0.1.0/lib/sinetex/error.ex#L1)

A protocol error, as defined by the security error table of the
*Manual de Segurança do SFN* (§5.5.1).

Fields:

  * `:c03` - the error code that goes in field C03 of the header
    (`0x01`..`0x14`, or `0xFF`).
  * `:egen` - the matching GEN0004 error code (`"EGEN9901"`..`"EGEN9920"`),
    or `nil` for `0xFF`.
  * `:field` - the header field the error refers to (`:c01`..`:c15`,
    `:body`), or `nil`.
  * `:message` - a short description, in English.
  * `:reason` - the internal cause, **for logs only**. It may say more than
    `:c03` does (see the `c14_errors: :uniform` option of `Sinetex.open/2`),
    so do not send it to the counterparty.

The struct is an exception, so it can be raised, but `Sinetex` functions
always return it in an `{:error, error}` tuple.

# `code`

```elixir
@type code() :: 1..20 | 255
```

A C03 error code: `0x01`..`0x14` or `0xFF`.

# `field`

```elixir
@type field() ::
  :c01
  | :c02
  | :c04
  | :c06
  | :c07
  | :c08
  | :c09
  | :c10
  | :c11
  | :c12
  | :c13
  | :c14
  | :c15
  | :body
  | nil
```

# `t`

```elixir
@type t() :: %Sinetex.Error{
  __exception__: true,
  c03: code(),
  egen: String.t() | nil,
  field: field(),
  message: String.t(),
  reason: term()
}
```

# `code?`

```elixir
@spec code?(term()) :: boolean()
```

Returns `true` if `code` is a valid, non-zero C03 error code.

# `codes`

```elixir
@spec codes() :: [code(), ...]
```

All valid C03 error codes, in ascending order.

# `new`

```elixir
@spec new(code(), term()) :: t()
```

Builds the error for `code`, keeping `reason` for logs.

    iex> error = Sinetex.Error.new(0x0B)
    iex> {error.egen, error.field, error.message}
    {"EGEN9911", :c15, "invalid signature"}

---

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