ResponseHandler
in package
Handles HTTP responses from Horizon API and converts them to typed response objects
This class acts as a response factory and deserializer for all Horizon API requests. It takes raw HTTP responses from Guzzle, validates them, parses the JSON content, and instantiates the appropriate response class based on the request type. This central handler ensures consistent error handling and response processing across the SDK.
Response Processing Flow:
- Validates HTTP status code (handles 3xx+ errors)
- Parses JSON response body with error handling
- Routes to appropriate response class based on request type
- Attaches rate limit headers and HTTP client to response
- Returns fully hydrated, type-safe response object
The handler supports all Horizon API endpoints including accounts, transactions, operations, effects, ledgers, offers, liquidity pools, and SEP protocol responses.
Tags
Table of Contents
Methods
- handleResponse() : Response
- Converts an HTTP response into a typed Horizon response object
Methods
handleResponse()
Converts an HTTP response into a typed Horizon response object
public
handleResponse(ResponseInterface $response, string $requestType, Client $httpClient) : Response
This method processes the raw HTTP response, validates the status code, parses the JSON body, and instantiates the appropriate response class based on the request type. It handles all response types from Horizon API endpoints and SEP protocol services.
Parameters
- $response : ResponseInterface
-
The HTTP response from Guzzle
- $requestType : string
-
The type of request (from RequestType constants)
- $httpClient : Client
-
The HTTP client for pagination requests
Tags
Return values
Response —The typed response object with parsed data