当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::isClientError方法代码示例

本文整理汇总了PHP中Guzzle\Http\Message\Response::isClientError方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::isClientError方法的具体用法?PHP Response::isClientError怎么用?PHP Response::isClientError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Http\Message\Response的用法示例。


在下文中一共展示了Response::isClientError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getDelay

 /**
  * {@inheritdoc}
  */
 protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response && $response->isClientError()) {
         $parts = $this->parser->parse($response);
         return $parts['code'] == 'ProvisionedThroughputExceededException' || $parts['code'] == 'ThrottlingException' ? true : null;
     }
 }
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:10,代码来源:ThrottlingErrorChecker.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: getDelay

 /**
  * {@inheritdoc}
  */
 protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response && $response->isClientError()) {
         $parts = $this->exceptionParser->parse($request, $response);
         return isset(self::$throttlingExceptions[$parts['code']]) ? true : null;
     }
 }
开发者ID:ebeauchamps,项目名称:brilliantretail,代码行数:10,代码来源:ThrottlingErrorChecker.php

示例4: 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

示例5: 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

示例6: parse

 /**
  * {@inheritdoc}
  */
 public function parse(RequestInterface $request, Response $response)
 {
     $data = array('code' => null, 'message' => null, 'type' => $response->isClientError() ? 'client' : 'server', 'request_id' => null, 'parsed' => null);
     if ($body = $response->getBody(true)) {
         $this->parseBody(new \SimpleXMLElement($body), $data);
     } else {
         $this->parseHeaders($request, $response, $data);
     }
     return $data;
 }
开发者ID:ChengHuaUESTC,项目名称:mssapi_php,代码行数:13,代码来源:DefaultXmlExceptionParser.php

示例7: parse

 /**
  * {@inheritdoc}
  */
 public function parse(Response $response)
 {
     $data = array('code' => null, 'message' => null, 'type' => $response->isClientError() ? 'client' : 'server', 'request_id' => (string) $response->getHeader('x-amzn-RequestId'), 'parsed' => null);
     if (null !== ($json = json_decode($response->getBody(true), true))) {
         $data['parsed'] = $json;
         $json = array_change_key_case($json);
         $data = $this->doParse($data, $json);
     }
     return $data;
 }
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:13,代码来源:AbstractJsonExceptionParser.php

示例8: parse

 /**
  * {@inheritdoc}
  */
 public function parse(Response $response)
 {
     // Build array of default error data
     $data = array('code' => null, 'message' => null, 'errors' => array(), 'type' => $response->isClientError() ? 'client' : 'server', 'parsed' => null);
     // Parse the json
     if (null !== ($json = json_decode($response->getBody(true), true))) {
         $data['parsed'] = $json;
     }
     // Do additional, protocol-specific parsing and return the result
     return $this->doParse($data, $response);
 }
开发者ID:sajari,项目名称:sajari-sdk-php,代码行数:14,代码来源:AbstractJsonExceptionParser.php

示例9: factory

 public static function factory(RequestInterface $request, Response $response)
 {
     $response_json = $response->json();
     $generic_error = null;
     $cls = null;
     $is_lc_error = static::isLCApiError($response_json);
     $err_code = null;
     $err_message = null;
     $err_domain = null;
     $err_exception = null;
     $err_trace = null;
     $validation_failures = array();
     if ($is_lc_error) {
         $err_code = isset($response_json['error']['code']) ? $response_json['error']['code'] : null;
         $err_message = isset($response_json['error']['message']) ? $response_json['error']['message'] : null;
         $err_domain = isset($response_json['error']['domain']) ? $response_json['error']['domain'] : null;
         $err_exception = isset($response_json['error']['exception']) ? $response_json['error']['exception'] : null;
         $err_trace = isset($response_json['error']['trace']) ? $response_json['error']['trace'] : null;
         // parse validation failures
         $failures = isset($response_json['error']['validation_failures']) ? $response_json['error']['validation_failures'] : null;
         if ($failures) {
             foreach ($failures as $failure) {
                 $validation_failures[] = new ValidationFailure(isset($failure['name']) ? $failure['name'] : null, isset($failure['message']) ? $failure['message'] : null, isset($failure['extra_data']) ? $failure['extra_data'] : null);
                 unset($failure);
             }
         }
     } else {
         $err_message = 'Server communication error';
     }
     if ($is_lc_error) {
         $cls = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isClientError()) {
         $cls = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $cls = __CLASS__;
     }
     /** @var Payin7APIException $e */
     $e = new $cls($err_message);
     $e->setResponse($response);
     $e->setRequest($request);
     $e->setServerErrorCode($err_code);
     $e->setServerErrorMessage($err_message);
     $e->setServerErrorDomain($err_domain);
     $e->setServerErrorException($err_exception);
     $e->setServerErrorTrace($err_trace);
     $e->setServerValidationFailures($validation_failures);
     return $e;
 }
开发者ID:payin7-payments,项目名称:payin7-php,代码行数:48,代码来源:Payin7APIException.php

示例10: parse

 /**
  * {@inheritdoc}
  */
 public function parse(RequestInterface $request, Response $response)
 {
     // Build array of default error data
     $data = array('code' => null, 'message' => null, 'type' => $response->isClientError() ? 'client' : 'server', 'request_id' => (string) $response->getHeader('x-amzn-RequestId'), 'parsed' => null);
     // Parse the json and normalize key casings
     if (null !== ($json = json_decode($response->getBody(true), true))) {
         $data['parsed'] = array_change_key_case($json);
     }
     // Do additional, protocol-specific parsing and return the result
     $data = $this->doParse($data, $response);
     // Remove "Fault" suffix from exception names
     if (isset($data['code']) && strpos($data['code'], 'Fault')) {
         $data['code'] = preg_replace('/^([a-zA-Z]+)Fault$/', '$1', $data['code']);
     }
     return $data;
 }
开发者ID:Trideon,项目名称:gigolo,代码行数:19,代码来源:AbstractJsonExceptionParser.php

示例11: 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

示例12: parse

 /**
  * {@inheritdoc}
  */
 public function parse(RequestInterface $request, Response $response)
 {
     $data = array('type' => $response->isClientError() ? ExceptionParserInterface::TYPE_CLIENT : ExceptionParserInterface::TYPE_SERVER, 'code' => null, 'message' => null, 'errors' => array(), 'data' => json_decode($response->getBody(true), true));
     if (isset($data['data']['errorCode'])) {
         $data['code'] = $data['data']['errorCode'];
     }
     if (isset($data['data']['message'])) {
         $data['message'] = $data['data']['message'];
     }
     if (isset($data['data']['errors']) && is_array($data['data']['errors'])) {
         $data['errors'] = array();
         foreach ($data['data']['errors'] as $name => $message) {
             $data['errors'][] = array($name => trim($message));
         }
     }
     return $data;
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:20,代码来源:JsonExceptionParser.php

示例13: 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

示例14: getDelay

 protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
 {
     if ($response && $response->isClientError()) {
         $parts = $this->exceptionParser->parse($request, $response);
         if (!isset($this->retryable[$parts['code']]) || !$request->getClient()) {
             return null;
         }
         /** @var $client AwsClientInterface */
         $client = $request->getClient();
         // Only retry if the credentials can be refreshed
         if (!$client->getCredentials() instanceof AbstractRefreshableCredentials) {
             return null;
         }
         // Resign the request using new credentials
         $client->getSignature()->signRequest($request, $client->getCredentials()->setExpiration(-1));
         // Retry immediately with no delay
         return 0;
     }
 }
开发者ID:Trideon,项目名称:gigolo,代码行数:19,代码来源:ExpiredCredentialsChecker.php

示例15: parse

 public function parse(RequestInterface $request, Response $response)
 {
     $data = array('code' => null, 'message' => null, 'type' => $response->isClientError() ? 'client' : 'server', 'request_id' => null, 'parsed' => null);
     $body = $response->getBody(true);
     if (!$body) {
         $this->parseHeaders($request, $response, $data);
         return $data;
     }
     try {
         $xml = new \SimpleXMLElement($body);
         $this->parseBody($xml, $data);
         return $data;
     } catch (\Exception $e) {
         // Gracefully handle parse errors. This could happen when the
         // server responds with a non-XML response (e.g., private beta
         // services).
         $data['code'] = 'PhpInternalXmlParseError';
         $data['message'] = 'A non-XML response was received';
         return $data;
     }
 }
开发者ID:skinnard,项目名称:FTL-2,代码行数:21,代码来源:DefaultXmlExceptionParser.php


注:本文中的Guzzle\Http\Message\Response::isClientError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。