Skip to content

Allow status codes, other than 200 #46

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

Open
Blusten23 opened this issue Mar 8, 2021 · 1 comment · May be fixed by #55
Open

Allow status codes, other than 200 #46

Blusten23 opened this issue Mar 8, 2021 · 1 comment · May be fixed by #55

Comments

@Blusten23
Copy link

Blusten23 commented Mar 8, 2021

Is your feature request related to a problem? Please describe.
Currently result.raise_for_status() raises the error but I would like to deal with status codes later on rather than to get an exception from the client. The issue is described here: graphql-python/gql#40

Describe the solution you'd like
Add a flag, raise_for_status=True/False in client.execute().

Describe alternatives you've considered
Comment out the result.raise_for_status() line

Additional context

@sferich888
Copy link

I also ran into this issue today as well; in that because of the use of 'raise_for_status', my underlying '400' error (and its message; that would allow me to debug the issue) was eaten/stripped away from me.

Suggested Code change to allow for this functionality to be disabled?

    def execute(
        self,
        query: str,
        variables: dict = None,
        operation_name: str = None,
        headers: dict = {},
        riase_for_status: bool = True,
        **kwargs: Any,
    ):
        """Make synchronous request to graphQL server."""
        request_body = self.__request_body(
            query=query, variables=variables, operation_name=operation_name
        )

        result = requests.post(
            self.endpoint,
            json=request_body,
            headers={**self.headers, **headers},
            **{**self.options, **kwargs},
        )

        if riase_for_status:
            result.raise_for_status()

        return result.json()

sferich888 added a commit to sferich888/python-graphql-client that referenced this issue Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants