# `LetMe.UnauthorizedError`
[🔗](https://github.com/woylie/let_me/blob/3.0.4/lib/let_me/unauthorized_error.ex#L1)

Raised by `c:LetMe.Policy.authorize!/4` if a request is unauthorized.

# `t`

```elixir
@type t() :: %LetMe.UnauthorizedError{
  __exception__: term(),
  expression: Spek.expression() | nil,
  message: String.t()
}
```

Struct returned or raised if an authorization check fails.

`expression` contains the parts of the policy expression that were evaluated
and their results. Checks are evaluated lazily. The evaluation order follows
the expression as `Spek.optimize/1` rewrote it at compile time, which is not
the order the `allow/1` and `deny/1` calls were written in.

The expression reflects the checks until a decision is made, but it does not
reflect the complete authorization policy.

# `new`

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

Returns an error struct with the given message and without an expression.

## Examples

    iex> LetMe.UnauthorizedError.new()
    %LetMe.UnauthorizedError{message: "unauthorized", expression: nil}

    iex> LetMe.UnauthorizedError.new("forbidden")
    %LetMe.UnauthorizedError{message: "forbidden", expression: nil}

---

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