Get server response info

@param \Phalcon\Http\Client\Response $response
@return array|mixed
@throws BaseException
11117
public function getResponse(\Phalcon\Http\Client\Response $response)
    {
        // parse json response
        $data = json_decode($response->body, true);

        if (isset($data['errors']) === true || $response->header->statusCode > self::MAX_SUCCESS_CODE) {

            $error = $data['errors'][0]['description'];
            throw new BaseException((new \ReflectionClass($this->config))->getShortName(), $error);
        }

        return ($this->debug === true) ? [$response->header, $data] : $data;
    }
272357
public function getResponseArray($response)
    {
        $return = [];

        if (!($response instanceof Response)) {
            $this->errors[] = [
                // this error is coming from us, not the Chargify API response
                'source'    => 'client',
                'attribute' => null,
                'kind'      => 'networking',
                'message'   => 'no response'
            ];

            return $return;
        }

        /**
         * add error for bad status codes
         */
        $code       = $response->getStatusCode();
        $errorCodes = [404, 401, 500];
        if (in_array($code, $errorCodes)) {
            $this->errors[] = [
                // this error is coming from us, not the Chargify API response
                'source'    => 'client',
                'attribute' => null,
                'kind'      => 'status_code',
                'message'   => 'Bad status code: ' . $code
            ];
        }

        $body = $response->getBody();
        $body = trim((string)$body);

        /**
         * Return early if we have an empty body, which we can't turn into an array
         * anyway. This happens in cases where the API returns a 404, and possibly
         * other status codes.
         */
        if (empty($body)) {
            return $return;
        }

        $return = json_decode($body, true);

        // set errors, if any
        if (!empty($return['result']['errors'])) {
            foreach ($return['result']['errors'] as $error) {
                $this->errors[] = $error;
            }
        }

        /**
         * NOTE: There is also, maybe, an errors array nested in $return['meta']['errors']
         *       Why is this API so inconsistent???!!!!!
         */

        return $return;
    }
783867
protected function serializeResponse($response)
    {
        /** @var ResponseInterface $response */
        $serialized = serialize([
            $response->getStatusCode(),
            $response->getHeaders(),
            $response->getBody()->getContents(),
        ]);

        //subsequent calls need to access the stream from the beginning
        $response->getBody()->rewind();

        return $serialized;
    }
955048
public function processResponse($response)
    {
        // SOAP, JSON, HTTP POST
        $storeId = null;

        $this->_debugData['processResponse begin'] = 'Begin to process Notification';

        if (empty($response)) {
            $this->_debugData['error'] = 'Response is empty, please check your webserver that the result url accepts parameters';
            $this->_debug($storeId);
            return array('response' => '401');
        }

        // Log the results in log file and adyen_debug table
        $this->_debugData['response'] = $response;
        Mage::getResourceModel('adyen/adyen_debug')->assignData($response);

//      $params = new Varien_Object($response);
        // Create Varien_Object from response (soap compatible)
        $params = new Varien_Object();
        foreach ($response as $code => $value) {
            $params->setData($code, $value);
        }

        $actionName = $this->_getRequest()->getActionName();

        // authenticate result url
        $authStatus = Mage::getModel('adyen/authenticate')->authenticate($actionName, $params);
        if (!$authStatus['authentication']) {
            $this->_debugData['error'] = 'Autentication failure please check your notification username and password. This must be the same in Magento as in the Adyen platform';
            $this->_debug($storeId);
            return array('response' => '401', 'message' => $authStatus['message']);
        }

        // skip notification if notification is REPORT_AVAILABLE
        $eventCode = trim($params->getData('eventCode'));
        if ($eventCode == Adyen_Payment_Model_Event::ADYEN_EVENT_REPORT_AVAILABLE) {
            $this->_debugData['processResponse info'] = 'Skip notification REPORT_AVAILABLE';
            $this->_debug($storeId);
            return;
        }

        $this->_declareCommonVariables($params);
        $isInvalidKcp = $this->_isInvalidKcp($this->_paymentMethod, $this->_value);
        if ($isInvalidKcp) {
            $this->_debugData['processResponse info'] = 'Skip notification for KCP and 0 amount';
            $this->_debug($storeId);
            return;
        }

        // check if notification is not duplicate
        if (!$this->_isDuplicate($params)) {
            $incrementId = $params->getData('merchantReference');

            if ($incrementId) {
                $this->_debugData['info'] = 'Add this notification with Order increment_id to queue: ' . $incrementId;
                $this->_addNotificationToQueue($params);
            } else {
                $this->_debugData['error'] = 'Empty merchantReference';
            }
        } else {
            $this->_debugData['processResponse info'] = 'Skipping duplicate notification';
        }

        $this->_debug($storeId);
    }
1133405
public function checkResponse($response) {
    if (!is_array($response)) {
      return FALSE;
    }

    $responseParams = array();
    foreach ($this->responseFields as $k => $mandatory) {
      if (isset($response[$k])) {
        $responseParams[$k] = $response[$k];
      }
      elseif (!isset($response[$k]) && $mandatory) {
        throw new \Exception('expected response field ' . $k . ' is missing');
      }
    }

    return $responseParams;
  }
978145
private function processHttpResponse($response)
    {
        if ($response === null) {
            return null;
        }

        switch ($this->fakeType) {
            case 'pngb64':
                $base64 = base64_encode($response->getBody());
                return 'data:image/png;base64,' . $base64;
            case 'object': // 'object' not supported yet, we return array instead.
            case 'array':
                return json_decode($response->getBody(), true);
            default:
                return $response->getBody()->__toString();
        }
    }
110630
public function serverInformation(): ResponseInterface
    {
        ob_start();
        phpinfo(INFO_ALL & ~INFO_CREDITS & ~INFO_LICENSE);
        $phpinfo = ob_get_clean();
        preg_match('%<body>(.*)</body>%s', $phpinfo, $matches);
        $phpinfo = $matches[1];

        return $this->viewResponse('admin/server-information', [
            'title'   => I18N::translate('Server information'),
            'phpinfo' => $phpinfo,
        ]);
    }
779336
protected function respond($response)
    {
        if (Arr::get($response, 'object') === 'list') {
            if (!empty($response['data'])) {
                foreach ($response['data'] as $responseItem) {
                    $success = Arr::get($responseItem, 'object', 'error') !== 'error';

                    $responses[] = $this->mapResponse($success, $responseItem);
                }

                return $responses;
            } else {
                $response = $response['data'];
            }
        }

        $success = Arr::get($response, 'object', 'error') !== 'error';

        return $this->mapResponse($success, $response);
    }
631456
protected static function getBody(PsrResponse $response)
    {
        $stream = $response->getBody();
        if ($stream->getMetadata('wrapper_type') === 'plainfile') {
            return ['body' => '', 'file' => $stream->getMetadata('uri')];
        }
        if ($stream->getSize() === 0) {
            return ['body' => '', 'file' => false];
        }
        $stream->rewind();

        return ['body' => $stream->getContents(), 'file' => false];
    }
329426
protected function fetchResponseError($response)
	{
		if (isset($response['error-code'])) {
			return [
				'code' => $response['error-code'],
				'message' => $response['message'],
			];
		} else if (isset($response['errorCode'])) {
			return [
				'code' => $response['errorCode'],
				'message' => $response['message'],
			];
		}
		return null;
	}
177678
protected function parseResponse(Response $response)
    {
        $contentType = explode(';', $response->getHeader('content-type'))[0];

        switch ($contentType) {
            case 'application/json':
            case 'application/vnd.api+json':
                return $response->json();

            case 'application/xml':
                return $response->xml();
        }

        throw new RuntimeException("Unsupported returned content-type [$contentType]");
    }
96668
protected function parse_result( $response ) {
		if ( is_wp_error( $response ) ) {
			return (object) [
				'success' => false,
				'version' => false,
				'error'   => $response->get_error_code(),
				'message' => $response->get_error_message(),
			];
		} else {
			$result = json_decode( $response );
			if ( is_null( $result ) ) {
				return (object) [
					'success' => false,
					'version' => false,
					'error'   => '500',
					'message' => 'Parser Error',
				];
			} else {
				return $result;
			}
		}
	}
1358918
private function _parseResponse(Response $response)
    {
        switch ($this->_format) {
            case self::FORMAT_JSON:
                return json_decode($response, $this->_isJsonDecodeAssoc);
                break;
            default:
                return $response;
        }
    }
342553
public function parse_meta_response( $response ) {
		if ( $this->validate_response( $response ) ) {
			return $response;
		}
		$arr      = [];
		$response = [ $response ];

		array_filter(
			$response,
			function ( $e ) use ( &$arr ) {
				$arr['private']      = $e->is_private;
				$arr['last_updated'] = $e->updated_on;
				$arr['watchers']     = 0;
				$arr['forks']        = 0;
				$arr['open_issues']  = 0;
			}
		);

		return $arr;
	}
1228525
protected function getResultFromResponse(Response $response)
    {
        $result = [];

        foreach ($response->getData() as $element) {
            $item = $this->getAttributes($element);
            $item['type'] = $element['type'];
            $result[] = new ElasticIndexer($item);
        }

        return $result;
    }
1208196
private function processResponse($response) {
        list($status, $headers, $body) = $response;
        // if empty response just return boolean
        if ($status == 204) {
            return true;
        }
        
        $decoded = json_decode($body, true);
        if ($decoded === null) {
            throw new RestException('Could not decode response body as JSON.', $status);
        }
        if (200 <= $status && $status < 300) {
            return $decoded;
        }

        throw new RestException(
            $decoded['message'],
            $decoded['code'],
            (isset($decoded['errors']) ? $decoded['errors'] : null)
        );
    }
1081767
protected static function parseJSONResponse($response)
    {
        $result = json_decode($response->body, true);
        if ($result == null) {
            $error = json_last_error();
            throw new Error(
                "Error parsing server response ({$response->responseCode}) - {$response->body}. Got - {$error}"
            );
        }

        return $result;
    }