當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::isServerError方法代碼示例

本文整理匯總了PHP中Guzzle\Http\Message\Response::isServerError方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::isServerError方法的具體用法?PHP Response::isServerError怎麽用?PHP Response::isServerError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Guzzle\Http\Message\Response的用法示例。


在下文中一共展示了Response::isServerError方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: factory

 /**
  * Simple exception factory for creating Intercom standardised exceptions
  *
  * @param RequestInterface $request The Request
  * @param Response $response The response
  * @return BadResponseException
  */
 public static function factory(RequestInterface $request, Response $response)
 {
     $response_json = $response->json();
     $intercom_unavailable_error = NULL;
     if (!static::isValidIntercomError($response_json)) {
         if ($response->isServerError()) {
             $label = 'Server error response';
             $class = __NAMESPACE__ . '\\ServerErrorResponseException';
             $intercom_unavailable_error = 'Service Unavailable: Back-end server is at capacity';
         } else {
             $label = 'Unsuccessful response';
             $class = __CLASS__;
         }
     } elseif ($response->isClientError()) {
         $label = 'Client error response';
         $class = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
         $class = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new $class($message);
     $e->setResponse($response);
     $e->setRequest($request);
     // Sets the errors if the error response is the standard Intercom error type
     if (static::isValidIntercomError($response_json)) {
         $e->setErrors($response_json['errors']);
     } elseif ($intercom_unavailable_error != NULL) {
         $e->setErrors(array('code' => 'service_unavailable', "message" => $intercom_unavailable_error));
     }
     return $e;
 }
開發者ID:scup,項目名稱:intercom-php,代碼行數:42,代碼來源:IntercomException.php

示例2: factory

 /**
  * Simple exception factory for creating Intercom standardised exceptions
  *
  * @param RequestInterface $request The Request
  * @param Response $response The response
  * @return BadResponseException
  */
 public static function factory(RequestInterface $request, Response $response)
 {
     if (!static::isValidIntercomError($response->json())) {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     } elseif ($response->isClientError()) {
         $label = 'Client error response';
         $class = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
         $class = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new $class($message);
     $e->setResponse($response);
     $e->setRequest($request);
     // Sets the errors if the error response is the standard Intercom error type
     if (static::isValidIntercomError($response->json())) {
         $e->setErrors($response->json()['errors']);
     }
     return $e;
 }
開發者ID:atlir,項目名稱:intercom-php,代碼行數:32,代碼來源:IntercomException.php

示例3: getPriorityFromResponse

 /**
  * @param Response $response
  * @return int
  */
 private function getPriorityFromResponse(Response $response)
 {
     if ($response->isServerError() || $response->getInfo('total_time') > 5) {
         return Logger::ERROR;
     }
     if ($response->isClientError() || $response->getInfo('total_time') > 1) {
         return Logger::WARNING;
     }
     return Logger::INFO;
 }
開發者ID:robertpisano,項目名稱:LeeLee,代碼行數:14,代碼來源:MonologGuzzleLogAdapter.php

示例4: factory

 /**
  * Factory method to create a new response exception based on the response code.
  *
  * @param RequestInterface $request  Request
  * @param Response         $response Response received
  * @param string           $label
  *
  * @return BadResponseException
  */
 public static function factory(RequestInterface $request, Response $response, $label = null)
 {
     if (!$label) {
         if ($response->isClientError()) {
             $label = 'Client error response';
         } elseif ($response->isServerError()) {
             $label = 'Server error response';
         } else {
             $label = 'Unsuccessful response';
         }
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl(), '[content type] ' . $response->getContentType(), '[response body] ' . $response->getBody(true)));
     $result = new static($message);
     $result->setResponse($response);
     $result->setRequest($request);
     return $result;
 }
開發者ID:aculvi,項目名稱:OroCRMMailChimpBundle,代碼行數:26,代碼來源:BadResponseException.php

示例5: factory

 public static function factory(RequestInterface $request, Response $response)
 {
     if ($response->isClientError()) {
         $label = 'Client error response';
         $class = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
         $class = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new self($message);
     $e->setResponse($response);
     $e->setRequest($request);
     return $e;
 }
開發者ID:karllhughes,項目名稱:clearbit-php,代碼行數:18,代碼來源:BadResponseException.php

示例6: testIsServerError

 /**
  * @covers Guzzle\Http\Message\Response::isServerError
  */
 public function testIsServerError()
 {
     $response = new Response(500);
     $this->assertTrue($response->isServerError());
     $response = new Response(400);
     $this->assertFalse($response->isServerError());
 }
開發者ID:KANU82,項目名稱:guzzle,代碼行數:10,代碼來源:ResponseTest.php

示例7: isServerError

 /**
  * {@inheritdoc}
  */
 public function isServerError()
 {
     return $this->response->isServerError();
 }
開發者ID:ramunasd,項目名稱:platform,代碼行數:7,代碼來源:GuzzleRestResponse.php


注:本文中的Guzzle\Http\Message\Response::isServerError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。