Ejemplo n.º 1
0
 /**
  * @param GuzzleException $guzzleException
  */
 public function setErrorResponse(GuzzleException $guzzleException)
 {
     $this->exception = $guzzleException;
     if ($guzzleException instanceof RequestException) {
         $this->response = $guzzleException->getResponse();
         $this->status = $this->response->getStatusCode();
     }
     $this->timeResponse = microtime(true);
 }
Ejemplo n.º 2
0
 /**
  * Converts a Guzzle exception into an Httplug exception.
  *
  * @param GuzzleExceptions\GuzzleException $exception
  * @param RequestInterface                 $request
  *
  * @return HttplugException
  */
 private function handleException(GuzzleExceptions\GuzzleException $exception, RequestInterface $request)
 {
     if ($exception instanceof GuzzleExceptions\SeekException) {
         return new HttplugException\RequestException($exception->getMessage(), $request, $exception);
     }
     if ($exception instanceof GuzzleExceptions\ConnectException) {
         return new HttplugException\NetworkException($exception->getMessage(), $exception->getRequest(), $exception);
     }
     if ($exception instanceof GuzzleExceptions\RequestException) {
         // Make sure we have a response for the HttpException
         if ($exception->hasResponse()) {
             return new HttplugException\HttpException($exception->getMessage(), $exception->getRequest(), $exception->getResponse(), $exception);
         }
         return new HttplugException\RequestException($exception->getMessage(), $exception->getRequest(), $exception);
     }
     return new HttplugException\TransferException($exception->getMessage(), 0, $exception);
 }
Ejemplo n.º 3
0
 protected function parseException(GuzzleException $e)
 {
     $exceptionMapping = ['client' => [['statusCode' => 404, 'match' => '/ProductNotFound/i', 'exception' => '\\Dandomain\\Api\\Exception\\ProductNotFoundException'], ['statusCode' => 400, 'match' => '/ShippingMethodNotValid/i', 'exception' => '\\Dandomain\\Api\\Exception\\ShippingMethodNotValidException']]];
     if ($e instanceof ClientException) {
         /** @var ClientException $item */
         foreach ($exceptionMapping['client'] as $item) {
             if ($e->getResponse()->getStatusCode() == $item['statusCode'] && preg_match($item['match'], $e->getResponse()->getBody()->getContents())) {
                 /** @var ClientException $newE */
                 $newE = new $item['exception']($e->getMessage(), $e->getRequest(), $e->getResponse(), $e, $e->getHandlerContext());
                 return $newE;
             }
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Converts a Guzzle exception into a Novuso exception
  *
  * @param GuzzleExceptions\GuzzleException $exception The exception
  * @param RequestInterface                 $request   The request
  *
  * @return NovusoExceptions\Exception
  */
 protected function handleException(GuzzleExceptions\GuzzleException $exception, RequestInterface $request)
 {
     if ($exception instanceof GuzzleExceptions\SeekException) {
         return new NovusoExceptions\RequestException($exception->getMessage(), $request, $exception);
     }
     if ($exception instanceof GuzzleExceptions\ConnectException) {
         return new NovusoExceptions\NetworkException($exception->getMessage(), $exception->getRequest(), $exception);
     }
     if ($exception instanceof GuzzleExceptions\RequestException) {
         if ($exception->hasResponse()) {
             return new NovusoExceptions\HttpException($exception->getMessage(), $exception->getRequest(), $exception->getResponse(), $exception);
         }
         return new NovusoExceptions\RequestException($exception->getMessage(), $exception->getRequest(), $exception);
     }
     return new NovusoExceptions\TransferException($exception->getMessage(), 0, $exception);
 }
Ejemplo n.º 5
0
 /**
  * 处理短信接口的返回结果
  *
  * @param ResponseInterface|GuzzleException $response
  * @return array
  * @throws ProviderException
  * @throws GuzzleException
  */
 protected function handleResponse($response)
 {
     if ($response instanceof GuzzleException) {
         throw $response;
     }
     $parsedResponse = self::parseJson($response->getBody());
     if ($parsedResponse['statusCode'] != '000000') {
         throw new ProviderException($parsedResponse['statusMsg'], $parsedResponse['statusCode'], $parsedResponse);
     }
     return $parsedResponse;
 }