public function __construct(puzzle_exception_RequestException $delegate) { parent::__construct($delegate->getMessage(), $delegate->getCode()); $delegateRequest = $delegate->getRequest(); $this->_request = $delegateRequest instanceof tubepress_api_http_message_RequestInterface ? $delegateRequest : new tubepress_http_impl_puzzle_PuzzleBasedRequest($delegateRequest); $delegateResponse = $delegate->getResponse(); if ($delegateResponse !== null) { $this->_response = $delegateResponse instanceof tubepress_api_http_message_ResponseInterface ? $delegateResponse : new tubepress_http_impl_puzzle_PuzzleBasedResponse($delegateResponse); } }
public function testHasRequestAndResponse() { $req = new puzzle_message_Request('GET', '/'); $res = new puzzle_message_Response(200); $e = new puzzle_exception_RequestException('foo', $req, $res); $this->assertSame($req, $e->getRequest()); $this->assertSame($res, $e->getResponse()); $this->assertTrue($e->hasResponse()); $this->assertEquals('foo', $e->getMessage()); }
/** * Emits an error event for a request and accounts for the propagation * of an error event being stopped to prevent the exception from being * thrown. * * @param puzzle_adapter_TransactionInterface $transaction * @param Exception $e * @param array $stats * * @throws puzzle_exception_RequestException */ public static function emitError(puzzle_adapter_TransactionInterface $transaction, Exception $e, array $stats = array()) { $request = $transaction->getRequest(); // Convert non-request exception to a wrapped exception if (!$e instanceof puzzle_exception_RequestException) { $e = new puzzle_exception_RequestException($e->getMessage(), $request, null, $e); } // Mark the exception as having been emitted for an error event. This // works in tandem with the emitBefore method to prevent the error // event from being triggered twice for the same exception. $e->emittedError(true); // Dispatch an event and allow interception if (!$request->getEmitter()->emit('error', new puzzle_event_ErrorEvent($transaction, $e, $stats))->isPropagationStopped()) { throw $e; } }