# `Daraja.HTTPResponse`
[🔗](https://github.com/okothkongo/daraja/blob/v0.1.1/lib/daraja/http_response.ex#L1)

Maps HTTP status codes from Safaricom Daraja API responses before JSON parsing.

Daraja signals most application errors in the response body (`errorCode`,
`errorMessage`, or `ResponseCode`) and commonly uses HTTP **200** or **400** for
those payloads. Auth and infrastructure failures use other status codes and
should not be parsed as business-level success or error structs.

## Status handling

  * **2xx** and **400** — parse the body with the caller's parser (Daraja error
    envelope or success fields).
  * **401** / **403** — `{:error, :auth_failed, %Daraja.APIError{}}` (expired or
    invalid token).
  * **5xx** and other statuses — `{:error, :http_error, %Daraja.APIError{}}` for
    gateway or unexpected HTTP failures.

# `dispatch`

```elixir
@spec dispatch(
  Daraja.HTTPClient.status(),
  binary(),
  (binary(), Daraja.HTTPClient.status() -&gt; term())
) :: term()
```

---

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