public function __construct(array $data, Exception $exception = null)
 {
     $output = json_decode($data['output'], true);
     $this->error = $output['error'];
     $this->errors = $output['errors'];
     $this->shortMessage = $output['message'];
     $message = '';
     foreach ($this->errors as $k => $element) {
         if ($k) {
             $message .= '; ';
         }
         $message .= '[' . $element['error'] . '] ' . $element['message'] . ' (path: ' . ($element['path'] ?: 'null') . ', value: ' . ($element['value'] ?: 'null') . ')';
     }
     parent::__construct('[' . $output['error'] . '] ' . $output['message'] . ($message ? ': ' . $message : ''), $data['code'], $exception);
 }
 /**
  * @param array $data
  * @param bool $isContacts
  * @throws ActionException
  * @throws ClientException
  * @throws ContactsException
  * @throws HostException
  */
 protected function handleError(array $data, $isContacts)
 {
     if ($isContacts) {
         if ($data['code'] < 200 or $data['code'] > 299) {
             throw new ContactsException($data);
         }
     } else {
         $error = new ErrorResponse($data['output']);
         if ($error->isError()) {
             if (SmsapiException::isHostError($error->code)) {
                 throw new HostException($error->message, $error->code);
             } elseif (SmsapiException::isClientError($error->code)) {
                 throw new ClientException($error->message, $error->code);
             } else {
                 throw new ActionException($error->message, $error->code);
             }
         }
     }
 }
Пример #3
0
 /**
  * @param $data
  * @throws \SMSApi\Exception\ActionException
  * @throws \SMSApi\Exception\ClientException
  * @throws \SMSApi\Exception\HostException
  */
 protected function handleError($data)
 {
     $error = new \SMSApi\Api\Response\ErrorResponse($data);
     if ($error->isError()) {
         if (\SMSApi\Exception\SmsapiException::isHostError($error->code)) {
             throw new \SMSApi\Exception\HostException($error->message, $error->code);
         }
         if (\SMSApi\Exception\SmsapiException::isClientError($error->code)) {
             throw new \SMSApi\Exception\ClientException($error->message, $error->code);
         } else {
             throw new \SMSApi\Exception\ActionException($error->message, $error->code);
         }
     }
 }