You are here

class ServicesClientConnectionResponseException in Services Client 7

Same name and namespace in other branches
  1. 7.2 services_client_connection/include/exception.inc \ServicesClientConnectionResponseException

Common parent class for all services client module exceptions

Hierarchy

Expanded class hierarchy of ServicesClientConnectionResponseException

File

services_client_connection/include/exception.inc, line 25
Custom exception definitions

View source
class ServicesClientConnectionResponseException extends Exception {

  /**
   * Whole response that represents failed request
   *
   * @var ServicesClientConnectionResponse
   */
  public $response;

  /**
   * Request that has been made to server
   *
   * @var ServicesClientConnectionHttpRequest
   */
  public $request;
  public function __construct($response, $request, $message = NULL, $code = NULL) {

    // Save request and response source
    $this->response = $response;
    $this->request = $request;
    $message = empty($message) ? $this
      ->getServicesMessage() : $message;
    parent::__construct($message, $code);
  }

  /**
   * Dump request and response to watchdog
   *
   * @param $severity
   *   Watchdog severity default set to ERROR
   */
  public function log($severity = WATCHDOG_ERROR) {
    watchdog('scc', 'Request: <pre>@request</pre> Error response: <pre>@response</pre>', array(
      '@request' => print_r($this->request, TRUE),
      '@response' => print_r($this->response, TRUE),
    ), $severity);
  }

  /**
   * Provide human readable error mesage.
   */
  public function getServicesMessage() {
    $msg = $this->response->error_code . ' ' . $this->response->error_message;
    if (!empty($this->response->services_error)) {
      $msg .= ': ' . $this->response->services_error;
    }
    return $msg;
  }

  /**
   * Return error reponse code.
   *
   * @return int
   *   HTTP or cURL error code.
   */
  public function getErrorCode() {
    return $this->response->error_code;
  }

  /**
   * Return error response message.
   *
   * @return string
   *   Descritpion message.
   */
  public function getErrorMessage() {
    return $this->response->error_message;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ServicesClientConnectionResponseException::$request public property Request that has been made to server
ServicesClientConnectionResponseException::$response public property Whole response that represents failed request
ServicesClientConnectionResponseException::getErrorCode public function Return error reponse code.
ServicesClientConnectionResponseException::getErrorMessage public function Return error response message.
ServicesClientConnectionResponseException::getServicesMessage public function Provide human readable error mesage.
ServicesClientConnectionResponseException::log public function Dump request and response to watchdog
ServicesClientConnectionResponseException::__construct public function