protected function processResponse(ResponseInterface $httpResponse)
    {
        // Attempt to build the API response from the HTTP response body.
        $apiResponse = json_decode($httpResponse->getBody()->getContents());
        $httpResponse->getBody()->rewind(); // Rewind the stream to make future access easier.

        // Check for API errors.
        // @see https://devcenter.heroku.com/articles/platform-api-reference#statuses
        // @see https://devcenter.heroku.com/articles/platform-api-reference#errors
        if ($httpResponse->getStatusCode() >= 400) {
            throw new BadHttpStatusException(sprintf(
                'Heroku API error: HTTP code %s [%s] %s',
                $httpResponse->getStatusCode(),
                empty($apiResponse->id) ? 'no error ID found' : $apiResponse->id,
                empty($apiResponse->message) ? 'no error message found' : $apiResponse->message
            ));
        }

        // Check for JSON decoding errors.
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new JsonDecodingException(
                'JSON error while decoding Heroku API response: ' . json_last_error_msg()
            );
        }

        return $apiResponse;
    }