Skip to content
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

No means for retrieving response/body after InvalidArgumentException #349

Closed
strarsis opened this issue Sep 20, 2020 · 5 comments
Closed

Comments

@strarsis
Copy link

strarsis commented Sep 20, 2020

Description
Currently guzzle will throw an InvalidArgumentException when the status code of an HTTP response is outside of allowed range.
That exception comes without an instance to the response object, hence there is no way retrieving the response body.

How to reproduce
Perform a guzzle request and let it be answered with a status code that is outside of allowed range.

Possible Solution
Extend the InvalidArgumentException by a reference to the original, throwing response object.

Related
guzzle/guzzle#1105

@strarsis strarsis changed the title No means for retrieving body after InvalidArgumentException No means for retrieving response/body after InvalidArgumentException Sep 20, 2020
@Nyholm
Copy link
Member

Nyholm commented Oct 1, 2020

If the server answers with a status code that is not supported by the RFC, then we cannot create a Response object, ie, there is no response.

@Nyholm Nyholm closed this as completed Oct 1, 2020
@GrahamCampbell
Copy link
Member

Agreed.

@williamjulianvicary
Copy link

williamjulianvicary commented Oct 1, 2020

@Nyholm @GrahamCampbell - While I agree with you that a Response cannot be created, perhaps there is something we can do in terms of an Exception response here. At the moment it's impossible to see the headers/body of the response (due to the status codes and/or headers being malformed).

The body might be a challenge to handle properly given it's a stream, but dumping the headers into the exception I don't think is an unreasonable request, should they be available?

I appreciate sticking to the RFC with this stance, but the web is an irregular environment and if you're in no control of the endpoint being requested it basically makes the library unusable for those use-cases where an irregular response is out of your control.

For example:
https://github.com/guzzle/psr7/blob/master/src/Response.php#L156

This could be updated to add some context of the request details that caused the exception - the header asserts do this already:

throw new \InvalidArgumentException(

@Nyholm
Copy link
Member

Nyholm commented Oct 1, 2020

This PR is related: Nyholm/psr7#157

Please open an issue/pr on guzzle/psr7 about improving the exception message.

@strarsis
Copy link
Author

@Nyholm: This confused me first, this is a fork of guzzle/psr7?

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

No branches or pull requests

4 participants