Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @param string    $message  The exception message
  * @param int       $code     The exception $code
  * @param string    $value    The exception content
  * @param Exception $previous The previous exception that throwed that one
  */
 public function __construct($message, $code, $value, $previous = null)
 {
     switch ($code) {
         case self::CONNECTION_ERROR:
             $message = "Impossible to connect to Database Server : {$value}, {$message}";
             $details = array('server' => $value);
             break;
         case self::QUERY_ERROR:
             $message = "An error was detected : {$message} in the Database Query : {$value}";
             $details = array('query' => $value);
             App::logger()->error($message);
             break;
     }
     parent::__construct($message, $details);
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * @param int       $type     The type of exception
  * @param string    $file     The source file that caused this exception
  * @param Exception $previous The previous exception that caused that one
  */
 public function __construct($type, $file, $previous = null)
 {
     switch ($type) {
         case self::TYPE_FILE_NOT_FOUND:
             $message = "Error creating a view from template file {$file} : No such file or directory";
             $details = array('type' => $type, 'file' => $file);
             break;
         case self::TYPE_EVAL:
             $trace = array_map(function ($t) {
                 return $t['file'] . ':' . $t['line'];
             }, $previous->getTrace());
             $message = "An error occured while building the view from file {$file} : " . $previous->getMessage() . PHP_EOL . implode(PHP_EOL, $trace);
             $details = array('type' => $type, 'file' => $file, 'error' => $preivous->getMessage());
             break;
     }
     parent::__construct($message, $details);
 }
Ejemplo n.º 3
0
 public function __construct($message, $code, \Exception $previous = null)
 {
     $message .= ' : ' . $this->codeToMessage($code);
     parent::__construct($message, $code, $previous);
 }
Ejemplo n.º 4
0
 /**
  * @param Message\Request $request
  * @throws ApiException
  * @throws PaymentException
  * @throws SigningException
  * @return Message\Response
  */
 public function processRequest(Message\Request $request)
 {
     $response = NULL;
     try {
         foreach ($this->onRequest as $callback) {
             call_user_func($callback, $request);
         }
         try {
             $httpResponse = $this->sendHttpRequest($request);
         } catch (\Exception $e) {
             throw new ApiException($e->getMessage(), 0, $e);
         }
         switch ($httpResponse->getStatusCode()) {
             case ApiException::S400_BAD_REQUEST:
             case ApiException::S403_FORBIDDEN:
             case ApiException::S404_NOT_FOUND:
                 throw new ApiException('Payment is probably in wrong state or request is broken', $httpResponse->getStatusCode());
             case ApiException::S429_TOO_MANY_REQUESTS:
                 throw new ApiException('Too Many Requests', $httpResponse->getStatusCode());
             case ApiException::S503_SERVICE_UNAVAILABLE:
                 throw new ApiException('Service is down for maintenance', $httpResponse->getStatusCode());
         }
         $decoded = @json_decode($responseBody = $httpResponse->getBody(), TRUE);
         if ($decoded === NULL) {
             throw new ApiException(sprintf('API returned invalid json %s', $responseBody), $httpResponse->getStatusCode());
         }
         if (!isset($decoded['resultCode'])) {
             throw new ApiException(sprintf('The "resultCode" key is missing in response %s', $responseBody), $httpResponse->getStatusCode());
         }
         $response = new Message\Response($decoded, $request);
         if ($decoded['resultCode'] === PaymentException::INTERNAL_ERROR) {
             throw InternalErrorException::fromResponse($decoded, $response);
         }
         if (empty($decoded['signature'])) {
             throw new ApiException(sprintf('The "signature" key is missing or empty in response %s', $responseBody), $httpResponse->getStatusCode());
         }
         $response->verify($this->signature);
         switch ($decoded['resultCode']) {
             case PaymentException::MISSING_PARAMETER:
                 throw MissingParameterException::fromResponse($decoded, $response);
             case PaymentException::INVALID_PARAMETER:
                 throw InvalidParameterException::fromResponse($decoded, $response);
             case PaymentException::MERCHANT_BLOCKED:
                 throw MerchantBlockedException::fromResponse($decoded, $response);
             case PaymentException::SESSION_EXPIRED:
                 throw SessionExpiredException::fromResponse($decoded, $response);
             case PaymentException::PAYMENT_NOT_FOUND:
                 throw PaymentNotFoundException::fromResponse($decoded, $response);
             case PaymentException::PAYMENT_NOT_IN_VALID_STATE:
                 throw PaymentNotInValidStateException::fromResponse($decoded, $response);
         }
         foreach ($this->onResponse as $callback) {
             call_user_func($callback, $response);
         }
         return $response;
     } catch (Exception $e) {
         foreach ($this->onError as $callback) {
             call_user_func($callback, $e, $response);
         }
         throw $e;
     }
 }
Ejemplo n.º 5
0
 public function __construct($details = array())
 {
     $message = 'Missing Behavior Method';
     $details = 'The hook <code>' . $details['hook'] . '</code> could not find method <code>' . $details['behavior'] . '::' . $details['method'] . '()</code> could not be found.';
     parent::__construct($message, 0, $details);
 }