Get a request result.
Returns an array with a response body or and error code => reason.
@param \GuzzleHttp\Psr7\Response $response
@return array|mixed
764081
private function getResult($response)
    {
        $status = $response->getStatusCode();
        if ($status == 200) {
            return json_decode($response->getBody(), JSON_PRETTY_PRINT);
        } else {
            return [$status => $response->getReasonPhrase()];
        }
    }
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;
    }
332829
protected function _formatResult($response) {
		$result = array();
		foreach ($this->fields as $local => $stripe) {
			if (is_array($stripe)) {
				foreach ($stripe as $obj => $field) {
					if (isset($response->$obj->$field)) {
						$result[$local] = $response->$obj->$field;
					}
				}
			} else {
				if (isset($response->$stripe)) {
					$result[$local] = $response->$stripe;
				}
			}
		}
		// if no local fields match, return the default stripe_id
		if (empty($result)) {
			$result['stripe_id'] = $response->id;
		}
		return $result;
	}
724551
public function getResponse(\Phalcon\Http\Client\Response $response)
    {
        // parse json response

        $response = json_decode($response->body, true);

        if (isset($response['messages'][0]['error-text']) === true) {
            $error = $response['messages'][0]['error-text'];
            throw new BaseException((new \ReflectionClass($this->config))->getShortName(), $error);
        }

        if (isset($response['error-code']) === true) {
            $error = $response['error-code-label'];
            throw new BaseException((new \ReflectionClass($this->config))->getShortName(), $error);
        }
        return ($this->debug === true) ? [$response->header, $response] : $response;
    }
703314
private static function getErrorMessage($response)
    {
        $body = $response->getBody();

        $message = json_decode($body, true);
        $errors = [];

        if (is_array($message) && isset($message['errors'])) {
            $errors = $message['errors'];
        }

        if ($body == self::RATE_LIMIT_ERROR_MESSAGE) {
            $errors = [self::RATE_LIMIT_ERROR_MESSAGE];
        }

        return $errors;
    }
844196
protected function fetchCorreiosServices(Response $response)
    {
        $xml = simplexml_load_string($response->getBody()->getContents());
        $results = json_decode(json_encode($xml->Servicos))->cServico;

        if (! is_array($results)) {
            return [get_object_vars($results)];
        }

        return array_map('get_object_vars', $results);
    }
559322
protected function checkResponseForErrors($response)
    {
        if (isset($response["error"])) {
            $msg = [];
            $parts = ["code", "description", "details"];
            
            foreach ($parts as $part) {
                if (!empty($response["error"][$part])) {
                    $msg[] = $part.": ".$response["error"][$part];
                }
            }

            $msg = implode(" | ", $msg);
            $code = $response["error"]["code"];

            if (!array_key_exists($code, $this->exceptions)) {
                $code = "default";
            }

            throw new $this->exceptions[$code]($msg);
        }

        return $response;
    }
595415
protected function getResponse( $response ) {
		if ( is_string( $response ) ) {
			return Response::output( $response );
		}

		if ( is_array( $response ) ) {
			return Response::json( $response );
		}

		if ( $response instanceof ResponsableInterface ) {
			return $response->toResponse();
		}

		return $response;
	}
700649
public function makeSingle(Response $response)
    {
        if (!$response->getSuccess()) {
            return null;
        }

        $result = $this->getResultFromResponse($response);

        return $result[0] ?? null;
    }
1181502
public static function response($response)
    {
        $result = [];
        if (is_numeric($response)) {
            header('HTTP/1.1 '.$response);
            $result['status'] = $response;
            $result['status_message'] = self::toResponse($response);
            $result['data'] = [];
        } else {
            header('HTTP/1.1 '. 200);
            $result['status'] = 200;
            $result['status_message'] = 'Success';
            $result['data'] = self::superEncode($response);
        }

        $json_response = json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
        $json_response = str_replace('\\\\', '', $json_response);

        return $json_response;
    }
77991
protected function _setHeaders($response)
    {
        $headers = $this->getConfig('headers');

        if (!is_array($headers)) {
            return $response;
        }

        return $response
            ->withHeader($headers['limit'], (string)$this->getConfig('limit'))
            ->withHeader($headers['remaining'], (string)$this->_getRemainingConnections())
            ->withHeader(
                $headers['reset'],
                (string)Cache::read($this->_getCacheExpirationKey(), static::$cacheConfig)
            );
    }
1020796
private function extractError($response)
    {
        $error = array();
        $response = json_decode($response);
        if (property_exists($response, 'error')) {
            if (is_string($response->error->message)) {
                $message = $response->error->message;
            } elseif (is_object($response->error->message)) {
                $message = $response->error->message->value;
            } else {
                $message = "Unknown error";
            }
            $error['Message'] = $message;
            return $error;
        }
        return null;
    }
135220
public function fetchResponse($response, $result)
    {
        if ($result == 'obj') {
            return $response->fetchAll(\PDO::FETCH_OBJ);
        } elseif ($result == 'array_num') {
            return $response->fetchAll(\PDO::FETCH_NUM);
        } elseif ($result == 'array_assoc') {
            return $response->fetchAll(\PDO::FETCH_ASSOC);
        }
    }
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;
			}
		}
	}
157460
public static function decodeHttpResponse($response) {
    $code = $response->getResponseHttpCode();
    $body = $response->getResponseBody();
    $decoded = null;
    
    if ($code != '200' && $code != '201' && $code != '204') {
      $decoded = json_decode($body, true);
      $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
      if ($decoded != null && isset($decoded['error']['message'])  && isset($decoded['error']['code'])) {
        // if we're getting a json encoded error definition, use that instead of the raw response
        // body for improved readability
        $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}";
      } else {
        $err .= ": ($code) $body";
      }
      throw new Service\Exception($err, $code);
    }
    
    // Only attempt to decode the response, if the response code wasn't (204) 'no content'
    if ($code != '204') {
      $decoded = json_decode($body, true);
      if ($decoded == null) {
        throw new Service\Exception("Invalid json in service response: $body");
      }
    }
    return $decoded;
  }
1039264
public function parseData(array $response)
    {
        $key = str_replace('.', '_', $this->getMethod()) . '_response';
        return array_key_exists($key, $response) ? $response[$key] : null;
    }
877000
private function buildResults(Response $response): array
    {
        $data = $response->getData();
        $results = [];

        if (!isset($data['hits']['hits'])) {
            return $results;
        }

        foreach ($data['hits']['hits'] as $hit) {
            $results[] = new Result($hit);
        }

        return $results;
    }