Check an OAI-PMH response for errors that need to be handled.

@param object $result OAI-PMH response (SimpleXML object)

@return void

@throws \Exception
336546
protected function checkResponseForErrors($result)
    {
        // Detect errors and die if one is found:
        if ($result->error) {
            $attribs = $result->error->attributes();

            // If this is a bad resumption token error and we're trying to
            // restore a prior state, we should clean up.
            if ($attribs['code'] == 'badResumptionToken'
                && $this->stateManager->loadState()
            ) {
                $this->stateManager->clearState();
                throw new \Exception(
                    "Token expired; removing last_state.txt. Please restart harvest."
                );
            }
            throw new \Exception(
                "OAI-PMH error -- code: {$attribs['code']}, " .
                "value: {$result->error}"
            );
        }
    }
640823
private function processResults($results)
        {
            if (!empty($results->errors))
            {
                throw new ErrorFetchingTwitter();
            }

            $response = [];

            foreach ($results->statuses as $tweet)
            {
                $response[] = $tweet->text;
            }

            return $response;
        }
696955
public function response($result, $id, $error) {
        if ($error) { 
            $error['name'] = 'JSONRPCError';
        }
        return json_encode(array("jsonrpc" => "2.0",
                                 'result' => $result,
                                 'id' => $id,
                                 'error'=> $error));
    }
217979
protected function prepareAccessTokenResponse(array $result)
    {
        if ($this->getAccessTokenResourceOwnerId() !== null) {
            $result['resource_owner_id'] = $this->getValueByKey(
                $result,
                $this->getAccessTokenResourceOwnerId()
            );
        }
        return $result;
    }
479174
protected function result(&$result)
    {
        if (!empty($this->options['json'])) {
            $this->jsonResult($result, $this->options['json'], true);
        }

        if (!empty($this->options['with_attr'])) {
            $this->getResultAttr($result, $this->options['with_attr']);
        }
    }
809858
private function parseAccessToken(Result $result) {
        // If unexpected status code throw exception
        if ($result->getStatus() !== 200) {
            throw new OAuthException('Something went wrong requesting access token');
        }

        // Get the data form the result object
        $data = $result->getResult();

        // Store the data if available
        if (isset($data['access_token'])) {
            $this->setAccessToken($data['access_token']);
        }
        if (isset($data['refresh_token'])) {
            $this->setRefreshToken($data['refresh_token']);
        }
        if (isset($data['expire_time'])) {
            $this->setExpireTime(time() + $data['expire_time']);
        }
    }
807130
private function throwUsageExceptions( $result ) {
		if ( is_array( $result ) && array_key_exists( 'error', $result ) ) {
			throw new UsageException(
				$result['error']['code'],
				$result['error']['info'],
				$result
			);
		}
	}
155276
private function _CheckErrors($operation, $results)
	{
		if (is_soap_fault($results)) 
			throw new Exception("SOAP Fault: ".$results->faultcode."\n".$results->faultstring."\n", 4);
	}
1353215
private function matchesError($result, array $acceptor)
    {
        if ($result instanceof ApiException) {
            return $result->isConnectionError()
                || $result->getAwsErrorCode() == $acceptor['expected'];
        }

        return false;
    }
1341568
final protected function verifyResult($result)
    {
        $returnType = $this->returnType;
        if ($returnType === null) {
            if ($result !== null) {
                throw TypeMismatchException::format(
                        'Invalid return type from action handler %s: expecting null, %s given',
                        get_class($this), Debug::getType($result)
                );
            }

            return $result;
        }

        if (!($result instanceof $returnType)) {
            throw TypeMismatchException::format(
                    'Invalid return value from action handler %s: expecting %s, %s given',
                    get_class($this), $returnType, Debug::getType($result)
            );
        }

        return $result;
    }
171687
private function processResult(array $result)
    {
        $this->checkResponseStatus($result['http_code']);

        // Get decoded response data
        $responseArr = json_decode($result['response'], true);

        $this->checkJsonError();

        return $responseArr;
    }
1229223
protected function checkResultErrors(Mollie_Response $object)
	{
		if (!$object->isSuccess()) {
			throw new Mollie_Exception(strval($object->resultmessage), intval($object->resultcode));
		}
	}
1315659
public function setResult($result, $data = null)
    {
        if (null === $result) {
            return $this;
        }

        if (is_numeric($result)) {
            if ($result > 1000) {
                $result = ResultException::factory($result, $data);
            } else {
                $result = new static::$resultClass((int) $result, $data);
            }
        } elseif ($result instanceof ResultException) {
            // continue
        } elseif (is_array($result) && isset($result[self::RESULT_P_GLOBAL_CODE])) {
            $result = ResultException::factory($result[self::RESULT_P_GLOBAL_CODE], $result[self::RESULT_P_DATA]);
        } else {
            $result = new ResultException(ResultException::E_INTERNAL, $result);
        }

        if (!empty($data)) {
            $result->addData($data);
        }

        $this->result = $result;
        $this->setData(self::P_RESULT, [
            self::RESULT_P_GLOBAL_CODE => $result->getGlobalCode(),
            self::RESULT_P_DATA        => $result->getData(),
        ]);

        return $this;
    }
1161553
public function setResult($result = self::RESULT_SUCCESS,
                              $message = null,
                              array $data = [],
                              array $additional = [])
    {
        $this->headers->set('X-Phlexible-Response', 'result');

        $values = [
            'success' => $result,
            'msg' => $message,
            'data' => $data,
        ];

        if (is_array($additional) && count($additional)) {
            foreach ($additional as $key => $value) {
                $values += $additional;
            }
        }

        $this->setData($values);
    }
505052
private function renderResult(Result $result)
    {
        if ($result->hasNotices()) {
            /** @var Notice $notice */
            foreach ($result->getNotices() as $notice) {
                if (!empty($notice->getTitle())) {
                    $this->outputLine('<b>%s</b>: %s', [$notice->getTitle(), $notice->render()]);
                } else {
                    $this->outputLine($notice->render());
                }
            }
        }

        if ($result->hasErrors()) {
            /** @var Error $error */
            foreach ($result->getErrors() as $error) {
                $this->outputLine('<error>ERROR: %s</error>', [$error->render()]);
            }
        }
        if ($result->hasWarnings()) {
            /** @var Warning $warning */
            foreach ($result->getWarnings() as $warning) {
                if (!empty($warning->getTitle())) {
                    $this->outputLine('<b>%s</b>: <comment>%s</comment>', [$warning->getTitle(), $warning->render()]);
                } else {
                    $this->outputLine('<comment>%s</comment>', [$warning->render()]);
                }
            }
        }
        if (!$result->hasErrors() && !$result->hasWarnings()) {
            $this->outputLine('<success>OK</success>');
        }
    }
556754
public function buildResponse($result) {
        if ($result === false) {
            if ($curlErrorNumber = curl_errno($this->_ch)) {
                $curlErrorString = curl_error($this->_ch);
                $this->_error($curlErrorString);

                $exception = new ConnectionErrorException('Unable to connect to "'.$this->uri.'": '
                        . $curlErrorNumber . ' ' . $curlErrorString);

                $exception->setCurlErrorNumber($curlErrorNumber)
                    ->setCurlErrorString($curlErrorString);

                throw $exception;
            }

            $this->_error('Unable to connect to "'.$this->uri.'".');
            throw new ConnectionErrorException('Unable to connect to "'.$this->uri.'".');
        }

        $info = curl_getinfo($this->_ch);

        // Remove the "HTTP/1.x 200 Connection established" string and any other headers added by proxy
        $proxy_regex = "/HTTP\/1\.[01] 200 Connection established.*?\r\n\r\n/si";
        if ($this->hasProxy() && preg_match($proxy_regex, $result)) {
            $result = preg_replace($proxy_regex, '', $result);
        }

        $response = explode("\r\n\r\n", $result, 2 + $info['redirect_count']);

        $body = array_pop($response);
        $headers = array_pop($response);

        return new Response($body, $headers, $this, $info);
    }
1172915
private function checkResult($result, $vars = []) {
        if (!$result) {
            $this->isValidate = false;
            $vars[ 'attribute' ] = $this->as_name;
            $vars[ '1' ] = $this->p1;
            $vars[ '2' ] = $this->p2;
            $vars[ 'rule' ] = $this->rule;
            if ($this->msg_check) {
                $msg = Lang::get('validate', $this->msg_check, $vars);
                if (!$msg) {
                    $msg = $this->msg_check;
                }
            } else {
                $msg = Lang::get('validate', $this->check_role, $vars);
            }
            if ($this->is_throw) {
                throw new ValidateException($msg, 100010, null);
            } else {
                $this->msg = $msg;
            }
        }
        $this->p1 = null;
        $this->p2 = null;
        $this->rule = null;
    }