You are here

class RestException in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 src/Rest/RestException.php \Drupal\salesforce\Rest\RestException
  2. 5.0.x src/Rest/RestException.php \Drupal\salesforce\Rest\RestException

Class RestException.

@package Drupal\salesforce\Rest

Hierarchy

  • class \Drupal\salesforce\Rest\RestException extends \Drupal\salesforce\Rest\RuntimeException implements \Symfony\Component\Serializer\Exception\ExceptionInterface

Expanded class hierarchy of RestException

2 files declare their use of RestException
PullBase.php in modules/salesforce_pull/src/Plugin/QueueWorker/PullBase.php
SalesforceCommands.php in src/Commands/SalesforceCommands.php

File

src/Rest/RestException.php, line 13

Namespace

Drupal\salesforce\Rest
View source
class RestException extends \RuntimeException implements ExceptionInterface {

  /**
   * The current Response.
   *
   * @var \Psr\Http\Message\ResponseInterface|null
   */
  protected $response;

  /**
   * The response body.
   *
   * @var string
   */
  protected $body;

  /**
   * RestException constructor.
   *
   * @param \Psr\Http\Message\ResponseInterface|null $response
   *   A response, if available.
   * @param string $message
   *   Message (optional).
   * @param int $code
   *   Erorr code (optional).
   * @param \Exception|null $previous
   *   Previous exception (optional).
   */
  public function __construct(ResponseInterface $response = NULL, $message = "", $code = 0, \Exception $previous = NULL) {
    $this->response = $response;
    $message .= $this
      ->getResponseBody();
    parent::__construct($message, $code, $previous);
  }

  /**
   * Getter.
   *
   * @return null|\Psr\Http\Message\ResponseInterface
   *   The response.
   */
  public function getResponse() {
    return $this->response;
  }

  /**
   * Getter.
   *
   * @return string|null
   *   The response body.
   */
  public function getResponseBody() {
    if ($this->body) {
      return $this->body;
    }
    if (!$this->response) {
      return NULL;
    }
    $body = $this->response
      ->getBody();
    if ($body) {
      $this->body = $body
        ->getContents();
      return $this->body;
    }
    return '';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RestException::$body protected property The response body.
RestException::$response protected property The current Response.
RestException::getResponse public function Getter.
RestException::getResponseBody public function Getter.
RestException::__construct public function RestException constructor.