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

Default validateStatus function should print HTTP response body on error #459

Open
ace-n opened this issue Dec 16, 2021 · 3 comments
Open
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@ace-n
Copy link

ace-n commented Dec 16, 2021

Current behavior
If an HTTP request returns an invalid status code, gaxios will return a Request Failed with status code <CODE> error. (Relevant code here)

This doesn't give me lots of information as to why the error occurred (without wrapping the request call in a try...except block - this feels clunky IMHO), which is useful when debugging.

Expected behavior
gaxios should include the HTTP response body in the message - something like:

Error: Request failed with status code 500

Body:
  Some error occurred. Here is where the details should go.

Alternatively, validateStatus could be an opt-in behavior to allow for manual assertion of status code and/or response contents.

Workaround
In the meantime, I've been working around this by using a custom validateStatus function set to True.

@sofisl sofisl added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Dec 16, 2021
@sofisl
Copy link
Contributor

sofisl commented Dec 16, 2021

This sounds reasonable enough to me, @bcoe do you have any thoughts on this request?

@yoshi-automation yoshi-automation added triage me I really want to be triaged. and removed triage me I really want to be triaged. labels Dec 16, 2021
@bcoe
Copy link
Contributor

bcoe commented Dec 20, 2021

Agreed, seems like a reasonable request to me, @ace-n do you have a specific example of an error you were receiving so that we could see if the error was improved by this addition?

@ace-n
Copy link
Author

ace-n commented Apr 14, 2022

Create a Cloud Function like this:

exports.helloWorld = (req, res) => {
  res.status(404).send("Elvis has left the building").end();
};

Then, request it like this:

const x = async () => {
  const {request} = require('gaxios');
  const res = await request({
    url: '<FUNCTION_URL>'
  });
  console.log(res)
}

x()

It doesn't tell me that Elvis has left the building. 🎤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants