本文整理匯總了PHP中Zend_Http_Response::isError方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Http_Response::isError方法的具體用法?PHP Zend_Http_Response::isError怎麽用?PHP Zend_Http_Response::isError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend_Http_Response
的用法示例。
在下文中一共展示了Zend_Http_Response::isError方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
public function __construct(\Zend_Http_Response $httpResponse)
{
$this->_httpResponse = $httpResponse;
/*
if(!$httpResponse->isError() && !preg_match('/^\s*$/', $httpResponse->getBody()))
{
$this->_data = simplexml_load_string($httpResponse->getBody());
}
*/
if (!preg_match('/^\\s*$/', $httpResponse->getBody())) {
#print $httpResponse->getBody(); exit;
$this->_data = simplexml_load_string($httpResponse->getBody());
if ($httpResponse->isError()) {
$data = (array) $this->_data;
if (isset($data['error'])) {
$this->_error = $data['error'];
}
}
}
}
示例2: _checkResponse
/**
* Checks ReST response for errors.
*
* @param Zend_Http_Response $response the ReST response
* @return void
* @throws Zend_Service_Technorati_Exception
* @access protected
*/
protected static function _checkResponse(Zend_Http_Response $response)
{
if ($response->isError()) {
/**
* @see Zend_Service_Technorati_Exception
*/
// require_once 'Zend/Service/Technorati/Exception.php';
throw new Zend_Service_Technorati_Exception(sprintf('Invalid response status code (HTTP/%s %s %s)', $response->getVersion(), $response->getStatus(), $response->getMessage()));
}
}
示例3: _getData
/**
* Returns data of the call if there was no error
*
* @throws Robo47_Service_Bitly_Exception
* @param Zend_Http_Response $response
* @return string|array|object
*/
protected function _getData(Zend_Http_Response $response)
{
if ($response->isError()) {
$message = 'Error on api-call: ' . $response->getMessage();
throw new Robo47_Service_Bitly_Exception($message);
}
// find errors without parsing xml / json
// @todo parse formats always and move tests into the other switch
// and refactor a bit, method gets big and ugly
switch ($this->_format) {
case self::FORMAT_XML:
$regex = preg_quote('<errorCode>0</errorCode>', '/');
break;
case self::FORMAT_JSON:
$regex = preg_quote('"errorCode": 0', '/');
break;
}
if (!preg_match('/' . $regex . '/i', $response->getBody())) {
$message = 'Error on api-call: no errorCode=0 found';
throw new Robo47_Service_Bitly_Exception($message);
}
// @todo checking for errors ALWAYS!
switch ($this->_resultFormat) {
case self::FORMAT_RESULT_NATIVE:
$result = $response->getBody();
break;
case self::FORMAT_RESULT_ARRAY:
switch ($this->_format) {
case self::FORMAT_XML:
$result = $this->xmlToArray($response->getBody());
break;
case self::FORMAT_JSON:
$result = json_decode($response->getBody(), true);
break;
}
break;
case self::FORMAT_RESULT_OBJECT:
switch ($this->_format) {
case self::FORMAT_XML:
$result = $this->xmlToObject($response->getBody());
break;
case self::FORMAT_JSON:
$result = json_decode($response->getBody(), false);
break;
}
break;
}
return $result;
}
示例4: prepareResponse
/**
* Prepare a solarium response from the given request and client
* response
*
* @throws HttpException
* @param Request $request
* @param \Zend_Http_Response $response
* @return Response
*/
protected function prepareResponse($request, $response)
{
if ($response->isError()) {
throw new HttpException($response->getMessage(), $response->getStatus());
}
if ($request->getMethod() == Request::METHOD_HEAD) {
$data = '';
} else {
$data = $response->getBody();
}
// this is used because getHeaders doesn't return the HTTP header...
$headers = explode("\n", $response->getHeadersAsString());
return new Response($data, $headers);
}
示例5: _checkResponse
/**
* Checks ReST response for errors.
*
* @param Zend_Http_Response $response the ReST response
* @return void
* @throws Zend_Service_Technorati_Exception
* @access protected
*/
protected static function _checkResponse(Zend_Http_Response $response)
{
if ($response->isError()) {
throw new Zend_Service_Technorati_Exception(sprintf('Invalid response status code (HTTP/%s %s %s)', $response->getVersion(), $response->getStatus(), $response->getMessage()));
}
}
示例6: _parseResponse
/**
* Search for error from request.
*
* If any error is found a DOMDocument is returned, this object contains a
* DOMXPath object as "ebayFindingXPath" attribute.
*
* @param Zend_Http_Response $response
* @throws Zend_Service_Ebay_Trading_Exception When any error occurrs during request
* @return SimpleXMLElement
*/
protected function _parseResponse(Zend_Http_Response $response)
{
// error message
$message = '';
// first trying, loading XML
$xml = simplexml_load_string($response->getBody());
if (!$xml) {
$message = 'It was not possible to load XML returned.';
}
if ($xml->Ack != 'Success') {
$message = 'Ack not success.';
}
// second trying, check request status
if ($response->isError()) {
$message = $response->getMessage() . ' (HTTP status code #' . $response->getStatus() . ')';
}
// throw exception when an error was detected
if (strlen($message) > 0) {
/**
* @see Zend_Service_Ebay_Finding_Exception
*/
require_once 'Zend/Service/Ebay/Trading/Exception.php';
throw new Zend_Service_Ebay_Trading_Exception($message);
}
return $xml;
}
示例7: _parseResponse
/**
* Parse response object and check for errors
*
* @param \Zend_Http_Response $response
* @return stdClass
*/
protected function _parseResponse(\Zend_Http_Response $response)
{
if ($response->isError()) {
switch ($response->getStatus()) {
case 401:
throw new Exception('Postmark request error: Unauthorized - Missing or incorrect API Key header.');
break;
case 422:
$error = \Zend_Json::decode($response->getBody());
if (is_object($error)) {
throw new Exception(sprintf('Postmark request error: Unprocessable Entity - API error code %s, message: %s', $error->ErrorCode, $error->Message));
} else {
throw new Exception(sprintf('Postmark request error: Unprocessable Entity - API error code %s, message: %s', $error['ErrorCode'], $error['Message']));
}
break;
case 500:
throw new Exception('Postmark request error: Postmark Internal Server Error');
break;
default:
throw new Exception('Unknown error during request to Postmark server');
}
}
return \Zend_Json::decode($response->getBody());
}
示例8: initializeResponse
/**
* Initializes response object.
*
* @param Zend_Http_Response $response
*
* @return Jirafe_HttpConnection_Response
*/
protected function initializeResponse(Zend_Http_Response $response)
{
return new Jirafe_HttpConnection_Response($response->getBody(), $response->getHeaders(), $response->isError() ? $response->getStatus() : 0, $response->getMessage());
}
示例9: _parseResponse
/**
* Search for error from request.
*
* If any error is found a DOMDocument is returned, this object contains a
* DOMXPath object as "ebayFindingXPath" attribute.
*
* @param Zend_Http_Response $response
* @throws Zend_Service_Ebay_Trading_Exception When any error occurrs during request
* @return SimpleXMLElement
*/
protected function _parseResponse(Zend_Http_Response $response)
{
// error message
$message = '';
$xml = simplexml_load_string($response->getBody());
if (!$xml) {
$message = 'It was not possible to load XML returned.';
}
if ($xml->Ack != 'Success' && $xml->Ack != 'Warning') {
$message = "Ack not success: " . print_r($xml, true);
}
//var_dump($dom->Ack);die;
// second trying, check request status
if ($response->isError()) {
$message = $response->getMessage() . ' (HTTP status code #' . $response->getStatus() . ')';
}
// throw exception when an error was detected
if (strlen($message) > 0) {
/**
* @see Zend_Service_Ebay_Finding_Exception
*/
require_once 'Zend/Service/Ebay/Shopping/Exception.php';
throw new Zend_Service_Ebay_Shopping_Exception($message);
}
/*
$dom = new DOMDocument();
$dom->loadXML($response->getBody());
Zend_Debug::dump($dom->saveXML());
Zend_Debug::dump($xml);
*/
return $xml;
}