Skip to content

Displays server response when introspection failed #385

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
Dec 4, 2021

Conversation

aedm
Copy link
Contributor

@aedm aedm commented Aug 10, 2021

When GraphQL introspection fails, the server response may not necessarily be in JSON format. In that case, the CLI failed to parse and display the response.

This PR makes the CLI display the response error message in plain text.

Example

$ graphql-client introspect-schema --authorization <...> https://api.github.com/graphql

Result without this PR:

Something else happened. Status: 403
Error: error decoding response body: expected value at line 2 column 1
Location: [...]\graphql_client_cli-0.10.0\src\introspect_schema.rs:61:45

Result with this PR:

Error: HTTP 403 Forbidden: 
Request forbidden by administrative rules. Please make sure your request has a User-Agent header (http://developer.github.com/v3/#user-agent-required). Check https://developer.github.com for other possible causes.

@tomhoule
Copy link
Member

I think the status codes are implementation-dependent. I haven't spent a lot of time thinking about this, but what do you think of trying to parse the JSON response, and if that fails print the whole response?

@aedm
Copy link
Contributor Author

aedm commented Aug 17, 2021

I think the status codes are implementation-dependent. I haven't spent a lot of time thinking about this, but what do you think of trying to parse the JSON response, and if that fails print the whole response?

I assume the response JSON is only valuable if there's no error. Trying to parse the error response is certainly possible, but I'm uncertain about its utility.

Do you have a use case in mind where the error response would be processed further?

@aedm
Copy link
Contributor Author

aedm commented Sep 13, 2021

parse the JSON response, and if that fails print the whole response?

Done, please take a look.

Copy link
Member

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@tomhoule tomhoule merged commit 7e815db into graphql-rust:main Dec 4, 2021
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

Successfully merging this pull request may close these issues.

2 participants