Get the response from the server
if there are API error pass them to error handler function

@param array $response
@return null
@throws BadFunctionCallException
@throws InvalidArgumentException
@throws RuntimeException
15532
public function getResponse(array $response)
    {
        if (isset($response['error']['code'])) {
            $this->handleRpcErrors($response['error']);
        }

        return isset($response['result']) ? $response['result'] : null;
    }
1329921
protected function getErrorCode($response)
    {
        $code = Arr::get($response['error'], 'code', 'PaymentException');
        if (!isset($this->errorCodeMap[$code])) {
            $code = 'PaymentException';
        }

        return new ErrorCode($this->errorCodeMap[$code]);
    }
1044093
protected function _handleCallbackAction(ServerRequest $request, Response $response)
    {
        $this->_setupModelInstances();

        $config = $this->getConfig();
        $providerName = $request->getParam('provider');

        $profile = $this->_getProfile($providerName, $request);
        if (!$profile) {
            return $response->withLocation(
                Router::url($config['loginUrl'], true) . '?error=' . $this->_error
            );
        }

        $user = $this->_getUser($profile);
        if (!$user) {
            return $response->withLocation(
                Router::url($config['loginUrl'], true) . '?error=' . $this->_error
            );
        }

        $user->unsetProperty($config['fields']['password']);

        if (!$config['userEntity']) {
            $user = $user->toArray();
        }

        $event = $this->dispatchEvent(self::EVENT_AFTER_IDENTIFY, ['user' => $user]);
        $result = $event->getResult();
        if ($result !== null) {
            $user = $event->getResult();
        }

        $request->getSession()->write($config['sessionKey'], $user);

        return $response->withLocation(
            Router::url($this->_getRedirectUrl($request), true)
        );
    }
483383
protected function callErrorHandler($argument = null)
    {
        $this['response']->setStatus(500);

        ob_start();
        if (isset($this['error']) && is_callable($this['error'])) {
            call_user_func_array($this['error'], array($argument));
        } else {
            call_user_func_array(array($this, 'defaultError'), array($argument));
        }

        return ob_get_clean();
    }
147445
public static function parse(string $response) : Response
    {
        $responseObject = new Response();

        if (preg_match('/^HTTP\/([0-9]\.[0-9]) ([0-9]{3}) .*\r\n/', $response, $matches) !== 1) {
            throw new \RuntimeException('Could not parse response (error 1).');
        }

        [$line, $protocolVersion, $statusCode] = $matches;

        $responseObject->setProtocolVersion($protocolVersion);
        $responseObject->setStatusCode((int) $statusCode);

        $response = substr($response, strlen($line));

        for (;;) {
            $pos = strpos($response, Message::CRLF);
            if ($pos === false) {
                throw new \RuntimeException('Could not parse response (error 2).');
            }

            if ($pos === 0) {
                break;
            }

            $header = substr($response, 0, $pos);

            if (preg_match('/^(\S+):\s*(.*)$/', $header, $matches) !== 1) {
                throw new \RuntimeException('Could not parse response (error 3).');
            }

            [$line, $name, $value] = $matches;

            if (strtolower($name) === 'set-cookie') {
                $responseObject->setCookie(Cookie::parse($value));
            } else {
                $responseObject->addHeader($name, $value);
            }

            $response = substr($response, strlen($line) + 2);
        }

        $body = substr($response, 2);

        $responseObject->setContent($body);

        return $responseObject;
    }
914734
public static function decode_response($response)
    {
        if (!$response) {
            return PASSWORD_CONNECT_ERROR;
        }

        // $result should be `null` or `stdClass` object
        $result = json_decode($response);

        // The UAPI may return HTML instead of JSON on missing authentication
        if ($result && $result->status === 1) {
            return PASSWORD_SUCCESS;
        }

        if ($result && is_array($result->errors) && count($result->errors) > 0) {
            return array(
                'code'    => PASSWORD_ERROR,
                'message' => $result->errors[0],
            );
        }

        return PASSWORD_ERROR;
    }
554752
protected function decodeResponse($response)
	{
		$response = json_decode($response, true);
		if (is_null($response))
		{
			throw new RuntimeException('Closure Compiler service returned invalid JSON: ' . json_last_error_msg());
		}

		if (isset($response['serverErrors'][0]))
		{
			$error = $response['serverErrors'][0];

			throw new RuntimeException('Server error ' . $error['code'] . ': ' . $error['error']);
		}

		if (isset($response['errors'][0]))
		{
			$error = $response['errors'][0];

			throw new RuntimeException('Compilation error: ' . $error['error']);
		}

		return $response['compiledCode'];
	}
1225975
protected function raiseHtmlReceivedError($response)
    {
        libxml_use_internal_errors(true);
        $doc = new DOMDocument('1.0', 'utf-8');
        $doc->loadHTML($response);
        $body = $doc->getElementsByTagName('body');
        if ($body->length > 0) {
            $body = $body->item(0)->textContent;
        } else {
            $body = '';
        }
        throw new RuntimeException("HTML response received: $body", 702);
    }
246783
private function handleResponse($response)
    {

        if ($response instanceof View) {
            $content = $response->render();
        } elseif ($response instanceof Response) {
            $content = $response->getContent();
        } elseif ($response instanceof Request) {
            $content = $response->getResponse()->getContent();
        } elseif (is_string($response)) {
            $content = $response;
        } else {
            $content = false;
        }

        return $content;
    }
378693
protected function handleErrorResponse(Response $response)
    {
        $exception = $response->exception;

        $error = new MessageBag([
            'type'    => get_class($exception),
            'message' => $exception->getMessage(),
            'file'    => $exception->getFile(),
            'line'    => $exception->getLine(),
        ]);

        return back()->withInput()->withErrors($error, 'exception');
    }
39365
protected function processResponse($response)
    {
        // If the soap call failed then we need to throw an exception.
        $code = $this->soap->getResponseCode();
        if ($code != 200) {
            throw new \Exception(
                "SOAP client returned status of $code.",
                $code
            );
        }

        return $response;
    }
116187
private function resolveResponseArray(array $response)
    {
        if ($count = count($response)) {
            if ($count === 1) {
                $response = $response[0];
            }
        }
        $this->firing[] = $response;

        return $response;
    }
1212420
public static function handleError(BadResponseException $exception)
    {
        $response_body = (string) $exception->getResponse()->getBody();
        $array_body = decode($response_body);

        $code = $exception->getResponse()->getStatusCode();

        $lookForKeys = ['message', 'code', 'error'];

        foreach ($lookForKeys as $key) {
            if (isset($array_body[$key])) {
                $message = $array_body[$key];
            }
        }

        if (!$message) {
            $message = 'unknown_error';
        }

        throw new JSONError($message, $code, $array_body);
    }
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;
    }
188791
protected static function get_hold_response($response)
    {
        $iresponse = null;
        if (!is_null($response)) {
            if (is_string($response)) {
                $response = new Response(null, null, null, $response);
            }
            $iresponse = array();
            if (!is_null($response->code)) {
                $iresponse['code'] = $response->code;
            }
            if (!is_null($response->reason)) {
                $iresponse['reason'] = $response->reason;
            }
            if (!is_null($response->headers) && count($response->headers) > 0) {
                $iresponse['headers'] = $response->headers;
            }
            if (!is_null($response->body)) {
                if (Encoding::is_binary_data($response->body)) {
                    $iresponse['body-bin'] = base64_encode($response->body);
                } else {
                    $iresponse['body'] = $response->body;
                }
            }
        }
        return $iresponse;
    }
988994
protected function fetchResponseError($response)
	{
		if (isset($response['errors'])) {
			$first = reset($response['errors']);
			return [
				'code' => $first['code'],
				'message' => $first['message'],
			];
		}
		return null;
	}
440077
private function throwFromErrorResponse(HttpResponse $response, array $body)
    {
        list($message, $code, $extra) = $this->getErrorStringFromResponseBody($body);

        $exceptions = [
            400 => BadRequest::class,
            401 => Unauthorized::class,
            403 => Forbidden::class,
            404 => NotFound::class,
            406 => NotAcceptable::class,
            410 => Gone::class,
            420 => RateLimitTriggered::class,
            422 => UnprocessableEntity::class,
            429 => RateLimitTriggered::class,
            500 => ServerError::class,
            502 => BadGateway::class,
            503 => ServiceUnavailable::class,
            504 => GatewayTimeout::class,
        ];

        if (!array_key_exists($response->getStatus(), $exceptions)) {
            return;
        }

        throw new $exceptions[$response->getStatus()]($message, $code, null, $extra);
    }