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.
Summary
Functions
@spec dispatch( Daraja.HTTPClient.status(), binary(), (binary(), Daraja.HTTPClient.status() -> term()) ) :: term()