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


PHP RequestException::create方法代码示例

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


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

示例1: onComplete

 /**
  * Throw a RequestException if the response is not marked as successful.
  *
  * @param \GuzzleHttp\Event\CompleteEvent $event
  *
  * @throws \GuzzleHttp\Exception\RequestException
  *
  * @return void
  */
 public function onComplete(CompleteEvent $event)
 {
     $json = $event->getResponse()->json();
     if (array_get($json, 'result') !== 'success' || array_key_exists('response', $json) === false) {
         throw RequestException::create($event->getRequest(), $event->getResponse());
     }
 }
开发者ID:hoopyfrood,项目名称:Laravel-CloudFlare-API,代码行数:16,代码来源:ErrorSubscriber.php

示例2: testHasThrowState

 public function testHasThrowState()
 {
     $e = RequestException::create(new Request('GET', '/'), new Response(442));
     $this->assertFalse($e->getThrowImmediately());
     $e->setThrowImmediately(true);
     $this->assertTrue($e->getThrowImmediately());
 }
开发者ID:ChenOhayon,项目名称:sitepoint_codes,代码行数:7,代码来源:RequestExceptionTest.php

示例3: onComplete

 /**
  * Throw a RequestException on an HTTP protocol error
  *
  * @param CompleteEvent $event Emitted event
  * @throws RequestException
  */
 public function onComplete(CompleteEvent $event)
 {
     $code = (string) $event->getResponse()->getStatusCode();
     // Throw an exception for an unsuccessful response
     if ($code[0] === '4' || $code[0] === '5') {
         throw RequestException::create($event->getRequest(), $event->getResponse());
     }
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:14,代码来源:HttpError.php

示例4: magicCallResponseNotReceived

 /**
  * @test
  * @expectedException \GuzzleHttp\Exception\RequestException
  */
 public function magicCallResponseNotReceived()
 {
     $this->deferredHttpBinding = new FulfilledPromise($this->httpBindingMock);
     $this->httpBindingMock->method('request')->willReturn(new Request('POST', 'www.endpoint.com'))->with('someSoapMethod', [['some-key' => 'some-value']]);
     $this->httpBindingMock->expects($this->never())->method('response');
     $this->handlerMock->append(GuzzleRequestException::create(new Request('POST', 'www.endpoint.com')));
     $client = new SoapClient($this->clientMock, $this->deferredHttpBinding);
     $client->someSoapMethod(['some-key' => 'some-value'])->wait();
 }
开发者ID:meng-tian,项目名称:async-soap-guzzle,代码行数:13,代码来源:SoapClientTest.php

示例5: it_will_transform_exception_with_404_response

 /**
  * @test
  * @expectedException \Jsor\HalClient\Exception\BadResponseException
  */
 public function it_will_transform_exception_with_404_response()
 {
     $guzzleClient = $this->getMock('GuzzleHttp\\ClientInterface');
     $guzzleClient->expects($this->once())->method('send')->will($this->returnCallback(function ($request) {
         throw GuzzleRequestException::create($request, new Response(404));
     }));
     $client = new HalClient('http://propilex.herokuapp.com', new Guzzle6HttpClient($guzzleClient));
     $client->request('GET', '/');
 }
开发者ID:jsor,项目名称:hal-client,代码行数:13,代码来源:Guzzle6HttpClientTest.php

示例6: testBuild

 public function testBuild()
 {
     $request = new Request('GET', '/');
     $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\BadRequestException', ExceptionFactory::build(RequestException::create($request, new Response('400'))));
     $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\UnauthorizedException', ExceptionFactory::build(RequestException::create($request, new Response('401'))));
     $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\ForbiddenException', ExceptionFactory::build(RequestException::create($request, new Response('403'))));
     $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\NotFoundException', ExceptionFactory::build(RequestException::create($request, new Response('404'))));
     $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\MethodNotAllowedException', ExceptionFactory::build(RequestException::create($request, new Response('405'))));
     $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\NotAcceptableException', ExceptionFactory::build(RequestException::create($request, new Response('406'))));
     $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\RequestException', ExceptionFactory::build(RequestException::create($request, new Response('499'))));
 }
开发者ID:keika299,项目名称:chap,代码行数:11,代码来源:ExceptionFactoryTest.php

示例7: httpErrors

 /**
  * Middleware that throws exceptions for 4xx or 5xx responses when the
  * "http_error" request option is set to true.
  *
  * @return callable Returns a function that accepts the next handler.
  */
 public static function httpErrors()
 {
     return function (callable $handler) {
         return function ($request, array $options) use($handler) {
             if (empty($options['http_errors'])) {
                 return $handler($request, $options);
             }
             return $handler($request, $options)->then(function (ResponseInterface $response) use($request, $handler) {
                 $code = $response->getStatusCode();
                 if ($code < 400) {
                     return $response;
                 }
                 throw RequestException::create($request, $response);
             });
         };
     };
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:23,代码来源:Middleware.php

示例8: create

 /**
  * {@inheritdoc}
  */
 public static function create(HttpRequestInterface $request, HttpResponseInterface $response = null, Exception $previous = null, array $handlerContext = null)
 {
     if ($request instanceof RequestInterface && $response instanceof ResponseInterface) {
         static $clientErrorCodes = [-32600, -32601, -32602, -32700];
         $errorCode = $response->getRpcErrorCode();
         if (in_array($errorCode, $clientErrorCodes)) {
             $label = 'Client RPC error response';
             $className = __NAMESPACE__ . '\\ClientException';
         } else {
             $label = 'Server RPC error response';
             $className = __NAMESPACE__ . '\\ServerException';
         }
         $message = $label . ' [uri] ' . $request->getRequestTarget() . ' [method] ' . $request->getRpcMethod() . ' [error code] ' . $errorCode . ' [error message] ' . $response->getRpcErrorMessage();
         return new $className($message, $request, $response, $previous);
     }
     return parent::create($request, $response, $previous);
 }
开发者ID:yashb,项目名称:generator,代码行数:20,代码来源:RequestException.php

示例9: __invoke

 /**
  * @param RequestInterface $request
  * @param array            $options
  *
  * @return PromiseInterface
  */
 public function __invoke(RequestInterface $request, array $options)
 {
     $nextHandler = $this->nextHandler;
     if ($request->hasHeader('Authorization')) {
         return $nextHandler($request, $options);
     }
     $request = $request->withHeader('Authorization', sprintf('Bearer %s', $this->session->getToken()));
     return $nextHandler($request, $options)->then(function (ResponseInterface $response) use($request, $options) {
         $code = $response->getStatusCode();
         if ($code < 400) {
             return $response;
         }
         if ($response->hasHeader("WWW-Authenticate")) {
             throw BearerErrorResponseException::create($request, $response);
         }
         throw RequestException::create($request, $response);
     });
 }
开发者ID:easybiblabs,项目名称:oauth2-client-php,代码行数:24,代码来源:BearerAuthMiddleware.php

示例10: send

 /**
  * Use the send method to call every endpoint except for oauth/tokens
  *
  * @param HttpClient $client
  * @param string     $endPoint E.g. "/tickets.json"
  * @param array      $options
  *                             Available options are listed below:
  *                             array $queryParams Array of unencoded key-value pairs, e.g. ["ids" => "1,2,3,4"]
  *                             array $postFields Array of unencoded key-value pairs, e.g. ["filename" => "blah.png"]
  *                             string $method "GET", "POST", etc. Default is GET.
  *                             string $contentType Default is "application/json"
  *
  * @return \stdClass | null The response body, parsed from JSON into an object. Also returns null if something went wrong
  * @throws ApiResponseException
  * @throws AuthException
  */
 public static function send(HttpClient $client, $endPoint, $options = [])
 {
     $options = array_merge(['method' => 'GET', 'contentType' => 'application/json', 'postFields' => null, 'queryParams' => null], $options);
     $headers = array_merge(['Accept' => 'application/json', 'Content-Type' => $options['contentType'], 'User-Agent' => $client->getUserAgent()], $client->getHeaders());
     $request = new Request($options['method'], $client->getApiUrl() . $client->getApiBasePath() . $endPoint, $headers);
     $requestOptions = [];
     if (!empty($options['multipart'])) {
         $request = $request->withoutHeader('Content-Type');
         $requestOptions['multipart'] = $options['multipart'];
     } elseif (!empty($options['postFields'])) {
         $request = $request->withBody(\GuzzleHttp\Psr7\stream_for(json_encode($options['postFields'])));
     } elseif (!empty($options['file'])) {
         if (is_file($options['file'])) {
             $fileStream = new LazyOpenStream($options['file'], 'r');
             $request = $request->withBody($fileStream);
         }
     }
     if (!empty($options['queryParams'])) {
         foreach ($options['queryParams'] as $queryKey => $queryValue) {
             $uri = $request->getUri();
             $uri = $uri->withQueryValue($uri, $queryKey, $queryValue);
             $request = $request->withUri($uri, true);
         }
     }
     // \RockstarGames\Cake\Log\Log::debug($request);
     // \RockstarGames\Cake\Log\Log::debug($options);
     try {
         list($request, $requestOptions) = $client->getAuth()->prepareRequest($request, $requestOptions);
         $response = $client->guzzle->send($request, $requestOptions);
     } catch (RequestException $e) {
         $requestException = RequestException::create($e->getRequest(), $e->getResponse());
         throw new ApiResponseException($requestException);
     } finally {
         $client->setDebug($request->getHeaders(), $request->getBody()->getContents(), isset($response) ? $response->getStatusCode() : null, isset($response) ? $response->getHeaders() : null, isset($e) ? $e : null);
         $request->getBody()->rewind();
     }
     if (isset($file)) {
         fclose($file);
     }
     $client->setSideload(null);
     return json_decode($response->getBody()->getContents());
 }
开发者ID:patrickconroy,项目名称:zendesk_api_client_php,代码行数:58,代码来源:Http.php

示例11: testHandlesEmptyResponse

 /**
  * Test we can handle api exceptions when no response is returned from the API
  *
  * @expectedException Zendesk\API\Exceptions\ApiResponseException
  * @expectedExceptionMessage Error completing request
  */
 public function testHandlesEmptyResponse()
 {
     // Create an exception object which is thrown when a response couldn't be retrieved
     $unsuccessfulResponse = RequestException::create(new Request('GET', 'foo'), null);
     $this->mockApiResponses($unsuccessfulResponse);
     $this->dummyResource->create(['foo' => 'bar']);
 }
开发者ID:TengoInternet,项目名称:zendesk_api_client_php,代码行数:13,代码来源:ResourceTest.php

示例12: testHasStatusCodeAsExceptionCode

 public function testHasStatusCodeAsExceptionCode()
 {
     $e = RequestException::create(new Request('GET', '/'), new Response(442));
     $this->assertEquals(442, $e->getCode());
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:5,代码来源:RequestExceptionTest.php

示例13: exists

 /**
  * Check if a document exists.
  * 
  * {@internal It would be nice to do a HEAD requests here, but APIs often don't support it}}
  * 
  * @param string|array $id   ID or filter
  * @param array        $opts
  * @return boolean
  */
 public static function exists($id, array $opts = [])
 {
     $filter = is_array($id) ? $id : static::idToFilter($id);
     $query = static::filterToQuery($filter);
     $opts['parse'] = false;
     $opts['http_errors'] = false;
     $method = static::getExistsMethod();
     $response = static::getDB()->request($method, static::getUri(), compact('query') + $opts);
     $statusCode = $response->getStatusCode();
     if ($statusCode >= 400 && $statusCode != 404) {
         $request = static::getDB()->createRequest($method, static::getUri(), $query);
         throw RequestException::create($request, $response);
     }
     return $statusCode < 300;
     // Any 2xx code
 }
开发者ID:jasny,项目名称:db-rest,代码行数:25,代码来源:Implementation.php

示例14: getRequest

 /**
  * Handles all api calls
  * 
  * @param string $uri
  * @param array $params
  * @return array
  * @throws \Exception
  */
 public function getRequest($uri, array $params = [])
 {
     // validate uri
     if (!is_string($uri)) {
         throw new InvalidArgumentException("Invalid uri {$uri} submitted.");
     }
     // make sure uri isn't absolute - remove first / if there
     if ($uri[0] == '/') {
         $uri = substr($uri, 1);
     }
     try {
         $request = $this->client->createRequest('GET', $uri, ['query' => $params]);
         $response = $this->client->send($request)->json();
         // cairo returns 200 even for errors so check response for error
         // errors array can have multiple, which do we show? create one string for all?
         if (!empty($response['errors'])) {
             throw RequestException::create($request, new Response($response['errors'][0]['code'], [], null, ['reason_phrase' => $response['errors'][0]['messages'][0]]));
         }
     } catch (RequestException $e) {
         $message = $e->getRequest() . "\n";
         if ($e->hasResponse()) {
             $message .= $e->getResponse() . "\n";
         }
         throw new Exception($message, $e->getCode());
     }
     return $response;
 }
开发者ID:joeyrivera,项目名称:badgeville-php,代码行数:35,代码来源:Sites.php


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