/**
  * @param int               $code
  * @param RequestInterface  $request
  * @param array             $requestOptions
  * @param ResponseInterface $response
  * @param TransferInfo      $transferInfo
  * @param \Exception|null   $previous
  *
  * @throws \OutOfRangeException If the code is not recognized.
  */
 public function __construct($code, RequestInterface $request, array $requestOptions, ResponseInterface $response, TransferInfo $transferInfo, \Exception $previous = null)
 {
     $this->type = self::getTypeForCode($code);
     $this->request = $request;
     $this->requestOptions = $requestOptions;
     $this->response = $response;
     $this->transferInfo = $transferInfo;
     parent::__construct(sprintf('An error occurred while parsing the response: %s', $this->type), $code, $previous);
 }
Exemple #2
0
 /**
  * @param ProtocolException $exception
  *
  * @return E\ErrorInterface
  */
 private function getErrorForOxygenProtocolException(ProtocolException $exception)
 {
     if ($exception instanceof NetworkException) {
         // There was a network error; we did not get a full response.
         switch ($exception->getOriginalCode()) {
             case CURLE_COULDNT_RESOLVE_HOST:
                 // Hostname lookup failed.
                 return new E\Network\CanNotResolveHost();
             case CURLE_COULDNT_CONNECT:
                 return new E\Network\CanNotConnect();
             case CURLE_OPERATION_TIMEOUTED:
                 return new E\Network\TimedOut($exception->getTransferInfo()->total_time);
             case CURLE_SEND_ERROR:
                 return new E\Network\SendError();
             case CURLE_RECV_ERROR:
                 return new E\Network\ReceiveError();
             default:
                 return new E\Api\UnexpectedError();
         }
     } elseif ($exception instanceof ResponseException) {
         // We got a full response, but did not find the Oxygen module's response.
         if ($exception->getResponse()->hasHeader('www-authenticate') && $exception->getResponse()->getStatusCode() === 401) {
             // HTTP authorization encountered.
             $realm = '';
             preg_match('{^Basic realm="(.*)"$}i', $exception->getResponse()->getHeaderLine('www-authenticate'), $matches);
             if (!empty($matches[1])) {
                 $realm = $matches[1];
             }
             return new E\Response\Unauthorized($realm, $exception->getRequest()->hasHeader('authorize'));
         } else {
             // @todo: Add special handling for >=400 status codes.
             return new E\Response\OxygenNotFound();
         }
     } elseif ($exception instanceof OxygenException) {
         // We got an exception or a fatal error directly from the Oxygen module.
         $exceptionData = $exception->getExceptionData();
         // This is a fatal error or an exception.
         return new E\Oxygen\Error($exceptionData->getMessage(), $exception->getCode(), $exceptionData->getType(), $exceptionData->getFile(), $exceptionData->getLine(), $exceptionData->getTraceString());
     } else {
         // This should never ever happen.
         return new E\Api\UnexpectedError();
     }
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function is($code)
 {
     // Since we shifted the error code, reverse that here.
     return parent::is($code - self::SHIFT_ERROR_CODE);
 }
Exemple #4
0
 /**
  * @param ExceptionData     $exceptionData
  * @param RequestInterface  $request
  * @param array             $requestOptions
  * @param ResponseInterface $response
  * @param TransferInfo      $transferInfo
  */
 public function __construct(ExceptionData $exceptionData, RequestInterface $request, array $requestOptions, ResponseInterface $response, TransferInfo $transferInfo)
 {
     $this->exceptionData = $exceptionData;
     $this->request = $request;
     $this->requestOptions = $requestOptions;
     $this->response = $response;
     $this->transferInfo = $transferInfo;
     parent::__construct(sprintf('An error occurred in the Oxygen module: %s', $exceptionData->getType()), $exceptionData->getCode());
 }