File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -193,14 +193,17 @@ The `error` event will be emitted when the EventSource connection fails.
193193The event receives a single ` Exception ` argument for the error instance.
194194
195195``` php
196- $redis ->on('error', function (Exception $e) {
196+ $es ->on('error', function (Exception $e) {
197197 echo 'Error: ' . $e->getMessage() . PHP_EOL;
198198});
199199```
200200
201201The EventSource connection will be retried automatically when it is temporarily
202202disconnected. If the server sends a non-successful HTTP status code or an
203203invalid ` Content-Type ` response header, the connection will fail permanently.
204+ In this case, the ` error ` event will receive a
205+ [ ` ResponseException ` ] ( https://github.com/reactphp/http#responseexception )
206+ that provides access to the response via the ` getResponse() ` method.
204207
205208``` php
206209$es->on('error', function (Exception $e) use ($es) {
Original file line number Diff line number Diff line change 77use React \EventLoop \Loop ;
88use React \EventLoop \LoopInterface ;
99use React \Http \Browser ;
10+ use React \Http \Message \ResponseException ;
1011use React \Stream \ReadableStreamInterface ;
1112
1213/**
@@ -193,7 +194,8 @@ private function request()
193194 $ this ->request ->then (function (ResponseInterface $ response ) {
194195 if ($ response ->getStatusCode () !== 200 ) {
195196 $ this ->readyState = self ::CLOSED ;
196- $ this ->emit ('error ' , [new \UnexpectedValueException (
197+ $ this ->emit ('error ' , [new ResponseException (
198+ $ response ,
197199 'Expected "200 OK" response status, ' . $ this ->quote ($ response ->getStatusCode () . ' ' . $ response ->getReasonPhrase ()) . ' response status returned '
198200 )]);
199201 $ this ->close ();
@@ -204,7 +206,8 @@ private function request()
204206 $ contentType = $ response ->getHeaderLine ('Content-Type ' );
205207 if (!preg_match ('/^text\/event-stream(?:$|;)/i ' , $ contentType )) {
206208 $ this ->readyState = self ::CLOSED ;
207- $ this ->emit ('error ' , [new \UnexpectedValueException (
209+ $ this ->emit ('error ' , [new ResponseException (
210+ $ response ,
208211 'Expected "Content-Type: text/event-stream" response header, ' . (!$ response ->hasHeader ('Content-Type ' ) ? 'no "Content-Type" ' : $ this ->quote ('Content-Type: ' . $ contentType )) . ' response header returned '
209212 )]);
210213 $ this ->close ();
Original file line number Diff line number Diff line change @@ -268,8 +268,10 @@ public function testConstructorWillReportFatalErrorWhenGetResponseResolvesWithIn
268268 $ deferred ->resolve ($ response );
269269
270270 $ this ->assertEquals (EventSource::CLOSED , $ readyState );
271- $ this ->assertInstanceOf ('UnexpectedValueException ' , $ caught );
271+ $ this ->assertInstanceOf ('React\Http\Message\ResponseException ' , $ caught );
272272 $ this ->assertEquals ($ expectedMessage , $ caught ->getMessage ());
273+ $ this ->assertEquals ($ response ->getStatusCode (), $ caught ->getCode ());
274+ $ this ->assertSame ($ response , $ caught ->getResponse ());
273275 }
274276
275277 public function provideInvalidContentType ()
@@ -320,8 +322,9 @@ public function testConstructorWillReportFatalErrorWhenGetResponseResolvesWithIn
320322 $ deferred ->resolve ($ response );
321323
322324 $ this ->assertEquals (EventSource::CLOSED , $ readyState );
323- $ this ->assertInstanceOf ('UnexpectedValueException ' , $ caught );
325+ $ this ->assertInstanceOf ('React\Http\Message\ResponseException ' , $ caught );
324326 $ this ->assertEquals ($ expectedMessage , $ caught ->getMessage ());
327+ $ this ->assertSame ($ response , $ caught ->getResponse ());
325328 }
326329
327330 public function testConstructorWillReportOpenWhenGetResponseResolvesWithValidResponse ()
You can’t perform that action at this time.
0 commit comments