3
namespace GuzzleHttp\Event;
5
use GuzzleHttp\Adapter\TransactionInterface;
6
use GuzzleHttp\Exception\RequestException;
7
use GuzzleHttp\Message\ResponseInterface;
10
* Event object emitted after a request has been sent and an error was
13
* You may intercept the exception and inject a response into the event to
16
class ErrorEvent extends AbstractTransferEvent
21
* @param TransactionInterface $transaction Transaction that contains the request
22
* @param RequestException $e Exception encountered
23
* @param array $transferStats Array of transfer statistics
25
public function __construct(
26
TransactionInterface $transaction,
30
parent::__construct($transaction, $transferStats);
31
$this->exception = $e;
35
* Intercept the exception and inject a response
37
* @param ResponseInterface $response Response to set
39
public function intercept(ResponseInterface $response)
41
$this->stopPropagation();
42
$this->getTransaction()->setResponse($response);
43
$this->exception->setThrowImmediately(false);
44
RequestEvents::emitComplete($this->getTransaction());
48
* Get the exception that was encountered
50
* @return RequestException
52
public function getException()
54
return $this->exception;
58
* Get the response the was received (if any)
60
* @return ResponseInterface|null
62
public function getResponse()
64
return $this->getException()->getResponse();
68
* Request that a ParallelAdapterInterface throw the associated exception
69
* if the exception is unhandled.
71
* If the error event was not emitted from a ParallelAdapterInterface, then
72
* the effect of this method is nil.
74
* @param bool $throwImmediately Whether or not to throw immediately
76
public function throwImmediately($throwImmediately)
78
$this->exception->setThrowImmediately($throwImmediately);