Get more details from the response body, to add to error messages.

@param ResponseInterface $response

@return string
558467
public static function getErrorDetails(ResponseInterface $response)
    {
        $responseInfoProperties = [
            // Platform.sh API errors.
            'message',
            'detail',
            // RESTful module errors.
            'title',
            'type',
            // OAuth2 errors.
            'error',
            'error_description',
        ];

        $details = '';

        $response->getBody()->seek(0);
        $contents = $response->getBody()->getContents();

        try {
            $json = \GuzzleHttp\json_decode($contents, true);
            foreach ($responseInfoProperties as $property) {
                if (!empty($json[$property])) {
                    $value = $json[$property];
                    $details .= " [$property] " . (is_scalar($value) ? $value : json_encode($value));
                }
            }
        } catch (\InvalidArgumentException $parseException) {
            // Occasionally the response body may not be JSON.
            if ($contents) {
                $details .= " [extra] Non-JSON response body";
                $details .= " [body] " . $contents;
            }
            else {
                $details .= " [extra] Empty response body";
            }
        }

        return $details;
    }
631255
public static function getContent(ResponseInterface $response)
    {
        if ($response->getStatusCode() === 204) {
            return [];
        }

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

        if (!$body) {
            return [];
        }

        if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
            throw new DecodingFailedException('The content type header was not application/json.');
        }

        return self::jsonDecode($body);
    }
1342830
protected function normalizeResponse(ResponseInterface $response)
    {
        if (!is_null($this->normalizer)) {
            return $this->normalizer->normalize($response);
        }

        //default responsen is decoded json
        return $response->json();
    }
897507
protected function handleResponse(ResponseInterface $response)
    {
        $status = $response->getStatusCode();

        $data = (string) $response->getBody();
        $jsonResponseData = json_decode($data, false);
        $body = $data && $jsonResponseData === null ? $data : $jsonResponseData;

        return ['status_code' => $status, 'body' => $body];
    }
352754
protected function prepareContentLength(ResponseInterface $response)
    {
        if (!$response->hasHeader('content-length')) {
            if ($response->getBody()->getSize() !== null) {
                return $response->withHeader('content-length', (string) $response->getBody()->getSize());
            }
        }

        return $response;
    }
53610
private function messageFrom($response)
    {
        if (isset($response['Fault_Code']) && isset($response['Fault_String'])) {
            return $response['Fault_String'];
        } elseif (isset($response['Error_Number']) && $response['Error_Number'] != '0') {
            return $response['Error_Description'];
        } else {
            $result = isset($response['EXact_Message']) ? $response['EXact_Message'] : '';
            if (isset($response['Bank_Message']) && !empty($response['Bank_Message'])) {
                $result .= ' - ' . $response['Bank_Message'];
            }

            return $result;
        }
    }
497377
protected function parseResponse(ResponseInterface $response)
    {
        $response = json_decode($response->getBody()->getContents());

        if (isset($response->success) && $response->success) {
            return $response->data;
        }

        throw new \Exception($response->error_info, $response->error_code);
    }
1337846
public function processResponse(ResponseInterface $response)
    {

        $body = $response->getBody();

        $object = json_decode($body);
        if (json_last_error() === JSON_ERROR_NONE) {
            // JSON is valid
            if (property_exists($object, '_embedded') && property_exists($object->_embedded, 'items')) {
                $return = $object->_embedded->items;
            } elseif (property_exists($object, 'error')) {
                if (is_array($object->message)) {
                    foreach ($object->message as $message) {
                        $output .= $message;
                    }
                    throw new \Exception($output);
                } else {
                    throw new \Exception($object->message);
                }
            } else {
                $return = $object;
            }
        } else {
            $return = $body;
        }

        return $return;
    }
277369
public static function fromResponse(ResponseInterface $response)
    {
        $responseBody = (string) $response->getBody();
        if (empty($responseBody)) {
            return new self($response->getStatusCode(), $response->getReasonPhrase());
        }

        $decodedBody = json_decode($responseBody, true);
        if (!isset($decodedBody['error'])) {
            return new self($response->getStatusCode(), $response->getReasonPhrase());
        }

        $error = $decodedBody['error'];

        return new self($response->getStatusCode(), $error['message'], $error['type'], $error);
    }
1265976
public function formatSummary(
        RequestInterface $request,
        ResponseInterface $response = null
    ) {
        return sprintf(
            '%s %s',
            http_build_query($this->additionalSummaryInfo, '', ' '),
            $this->summaryMessageFormatter->format($request, $response)
        );
    }
879326
protected function configureResponse(ResponseInterface $Response){
        $Response->setRequest($this->Request);
        $Response->extract();
        return $Response;
    }
589296
public static function getHeader(ResponseInterface $response, $name)
    {
        $headers = $response->getHeader($name);

        return array_shift($headers);
    }
631037
static function decodeBody(\Psr\Http\Message\ResponseInterface $response) {
        $body = (string) $response->getBody();
        
        $type = $response->getHeader('Content-Type')[0];
        if(\stripos($type, 'text/html') !== false) {
            throw new \RuntimeException('Invalid API response: HTML response body received');
        }
        
        $json = \json_decode($body, true, 512, self::$jsonOptions);
        if($json === null && \json_last_error() !== \JSON_ERROR_NONE) {
            throw new \RuntimeException('Invalid API response: '.\json_last_error_msg());
        }
        
        return $json;
    }
568508
public static function getResponseLine(ResponseInterface $response): string
    {
        return sprintf(
            '%s %d%s',
            self::getProtocol($response),
            self::getStatus($response),
            ($response->getReasonPhrase() ? ' '.$response->getReasonPhrase() : '')
        );
    }
588157
protected function handleResponse( ResponseInterface $response ){

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

        // The expected response should always be JSON, thus now an array.
        if( !is_array($body) ){
            throw new Exception\ApiException( 'Malformed JSON response from server', $response->getStatusCode(), $body, $response );
        }

        return $body;

    }
1045214
public function getUrlOfResponse( ResponseInterface $response ) {
		$ref = InternalServer::storeResponse($this->tmpDir, $response);

		return $this->getServerRoot() . '/' . self::VND . '/' . $ref;
	}
1300977
protected function describe(RequestInterface $request, ResponseInterface $response = null)
    {
        if (!$response) {
            return sprintf('%s %s failed', $request->getMethod(), $request->getUri());
        }

        return sprintf(
            '%s %s returned %s %s',
            $request->getMethod(),
            $request->getUri(),
            $response->getStatusCode(),
            $response->getReasonPhrase()
        );
    }