# `Accrue.Processor.Stripe.ErrorMapper`
[🔗](https://github.com/szTheory/accrue/blob/accrue-v0.3.0/lib/accrue/processor/stripe/error_mapper.ex#L1)

Translates raw `LatticeStripe` error shapes into `Accrue.Error` subtypes
(D-07, PROC-07, OBS-06).

This is one of only two modules in the entire Accrue codebase allowed to
reference `LatticeStripe` — the other is `Accrue.Processor.Stripe`. The
facade-lockdown test in `test/accrue/processor/stripe_test.exs` enforces
this at CI time (T-PROC-02 mitigation).

## Mapping table

| LatticeStripe.Error.type       | Accrue error            |
| :----------------------------- | :---------------------- |
| `:card_error`                  | `%Accrue.CardError{}`   |
| `:rate_limit_error`            | `%Accrue.RateLimitError{}` |
| `:idempotency_error`           | `%Accrue.IdempotencyError{}` |
| `:invalid_request_error`       | `%Accrue.APIError{}`    |
| `:authentication_error`        | `%Accrue.APIError{}`    |
| `:api_error`                   | `%Accrue.APIError{}`    |
| `:connection_error`            | `%Accrue.APIError{}`    |
| anything else                  | `%Accrue.APIError{code: "unknown"}` |

## SignatureError raises, never returns

Per D-08, any webhook signature verification failure is raised, never
returned as a tuple. Both the typed
`%LatticeStripe.Webhook.SignatureVerificationError{}` struct and an
`invalid_request_error` with code `"signature_verification_failed"`
trigger an `Accrue.SignatureError` raise.

## Metadata preservation

The full raw error term is stashed in the Accrue error's `:processor_error`
field so operators can debug the original response. Per T-PROC-01, this
field MUST NOT be logged verbatim — downstream logging sanitizer is a
Plan 06 concern.

# `to_accrue_error`

```elixir
@spec to_accrue_error(term()) :: Exception.t()
```

Maps an arbitrary term (typically a `%LatticeStripe.Error{}`) to an
`Accrue.Error` subtype. Raises `Accrue.SignatureError` for signature
verification failures (never returns them).

---

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