Catch Guzzle parser exception#82
Catch Guzzle parser exception#82WyriHaximus merged 2 commits intoreactphp:masterfrom djagya:81-catch-guzzle-parse-request-exception
Conversation
src/Request.php
Outdated
| $this->stream->removeListener('error', array($this, 'handleError')); | ||
|
|
||
| $this->response = $response; | ||
| if (isset($response)) { |
There was a problem hiding this comment.
Functionally LGTM, but the changeset could be significantly smaller by using an early return above 👍
There was a problem hiding this comment.
Oh, you're right, let me fix it.
| list($response, $bodyChunk) = $this->parseResponse($this->buffer); | ||
| } catch (\InvalidArgumentException $exception) { | ||
| $this->emit('error', [$exception, $this]); | ||
| } |
There was a problem hiding this comment.
May I ask you to amend your changes to return within this block instead? :)
There was a problem hiding this comment.
Sure, I just wasn't sure if we need to clear the buffer and remove listeners if we emit an error.
Similar changes in react/http made me think that they must be removed/buffer must be cleared even if the response parsing was not successful.
Isn't that the case here?
There was a problem hiding this comment.
@djagya It looks like your analysis may be right and makes perfect sense here, sorry for the confusion 👍 Can you update this again?
src/Request.php
Outdated
| } catch (\InvalidArgumentException $exception) { | ||
| $this->emit('error', [$exception, $this]); | ||
|
|
||
| return; |
There was a problem hiding this comment.
Shouldn't we also unsubscribe from the stream as we do here https://github.com/djagya/http-client/blob/61bf248481da1101d432a57a9c2748a8af7016e0/src/Request.php#L145 since the response parsing has failed and nothing new coming from the stream could change that.
Ping @clue
|
Thanks 👍 |
See reactphp/http#65, #81
Catches Guzzle InvalidArgumentException exception when invalid data are parsed via
gPsr\parse_response