Skip to content

Commit 61bf248

Browse files
author
danil zakablukovskii
committed
catch Guzzle parser exception
1 parent 985f8a0 commit 61bf248

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/Request.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,13 @@ public function handleData($data)
132132
$this->buffer .= $data;
133133

134134
if (false !== strpos($this->buffer, "\r\n\r\n")) {
135-
list($response, $bodyChunk) = $this->parseResponse($this->buffer);
135+
try {
136+
list($response, $bodyChunk) = $this->parseResponse($this->buffer);
137+
} catch (\InvalidArgumentException $exception) {
138+
$this->emit('error', [$exception, $this]);
139+
140+
return;
141+
}
136142

137143
$this->buffer = null;
138144

tests/RequestTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,28 @@ public function requestShouldEmitErrorIfConnectionEmitsError()
220220
$request->handleError(new \Exception('test'));
221221
}
222222

223+
/** @test */
224+
public function requestShouldEmitErrorIfGuzzleParseThrowsException()
225+
{
226+
$requestData = new RequestData('GET', 'http://www.example.com');
227+
$request = new Request($this->connector, $requestData);
228+
229+
$this->successfulConnectionMock();
230+
231+
$handler = $this->createCallableMock();
232+
$handler->expects($this->once())
233+
->method('__invoke')
234+
->with(
235+
$this->isInstanceOf('\InvalidArgumentException'),
236+
$this->isInstanceOf('React\HttpClient\Request')
237+
);
238+
239+
$request->on('error', $handler);
240+
241+
$request->writeHead();
242+
$request->handleData("\r\n\r\n");
243+
}
244+
223245
/**
224246
* @test
225247
* @expectedException Exception

0 commit comments

Comments
 (0)