Skip to content

Catch Guzzle parser exception #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2017
Merged

Catch Guzzle parser exception #82

merged 2 commits into from
May 2, 2017

Conversation

djagya
Copy link
Contributor

@djagya djagya commented Apr 15, 2017

See reactphp/http#65, #81

Catches Guzzle InvalidArgumentException exception when invalid data are parsed via gPsr\parse_response

src/Request.php Outdated
@@ -141,22 +145,24 @@ public function handleData($data)
$this->stream->removeListener('end', array($this, 'handleEnd'));
$this->stream->removeListener('error', array($this, 'handleError'));

$this->response = $response;
if (isset($response)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally LGTM, but the changeset could be significantly smaller by using an early return above 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right, let me fix it.

list($response, $bodyChunk) = $this->parseResponse($this->buffer);
} catch (\InvalidArgumentException $exception) {
$this->emit('error', [$exception, $this]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask you to amend your changes to return within this block instead? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djagya It looks like your analysis may be right and makes perfect sense here, sorry for the confusion 👍 Can you update this again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clue done, sorry for the delay

src/Request.php Outdated
} catch (\InvalidArgumentException $exception) {
$this->emit('error', [$exception, $this]);

return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@clue clue added the bug label Apr 24, 2017
@WyriHaximus WyriHaximus merged commit 5815195 into reactphp:master May 2, 2017
@WyriHaximus
Copy link
Member

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy