2 namespace GuzzleHttp\Promise;
5 * A special exception that is thrown when waiting on a rejected promise.
7 * The reason value is available via the getReason() method.
9 class RejectionException extends \RuntimeException
11 /** @var mixed Rejection reason. */
15 * @param mixed $reason Rejection reason.
16 * @param string $description Optional description
18 public function __construct($reason, $description = null)
20 $this->reason = $reason;
22 $message = 'The promise was rejected';
25 $message .= ' with reason: ' . $description;
26 } elseif (is_string($reason)
27 || (is_object($reason) && method_exists($reason, '__toString'))
29 $message .= ' with reason: ' . $this->reason;
30 } elseif ($reason instanceof \JsonSerializable) {
31 $message .= ' with reason: '
32 . json_encode($this->reason, JSON_PRETTY_PRINT);
35 parent::__construct($message);
39 * Returns the rejection reason.
43 public function getReason()