Esempio n. 1
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;
 }
 /**
  * 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);
 }
Esempio n. 3
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);
 }